Wednesday, November 29, 2006

connecting btrieve database with vb6

you have an old version of btrieve and you want to read data from it?? well, you'r luck if you read this message in the beginning of your search... i lost 3 days of intensive searching.. and finaly found it. and here i share it with you...
well, open vb program and bla bla bla ...
now you should define some consts for easy work:
i suggest you to create a separate modul for this code (that what i did)
DefInt A-Z
Global Const BOPEN = 0
Global Const BCLOSE = 1
Global Const BINSERT = 2
Global Const BUPDATE = 3
Global Const BDELETE = 4
Global Const BGETEQUAL = 5
Global Const BGETNEXT = 6
Global Const BGETGREATEROREQUAL = 9
Global Const BGETFIRST = 12
Global Const BCREATE = 14
Global Const BSTAT = 15
Global Const BSTOP = 25
Global Const BVERSION = 26
Global Const BRESET = 28
Global Const KEY_BUF_LEN = 255

Rem Key FlagsGlobal Const DUP = 1
Global Const MODIFIABLE = 2
Global Const BIN = 4
Global Const NUL = 8
Global Const SEGMENT = 16
Global Const SEQ = 32
Global Const DEC = 64
Global Const SUP = 128
Rem Key Types
Global Const EXTTYPE = 256
Global Const MANUAL = 512
Global Const BSTRING = 0
Global Const BINTEGER = 1
Global Const BFLOAT = 2
Global Const BDATE = 3
Global Const BTIME = 4
Global Const BDECIMAL = 5
Global Const BNUMERIC = 8
Global Const BZSTRING = 11
Global Const BAUTOINC = 15

' now declare the function BTRCALL with do all the I\O with the database
Private Declare Function BTRCALL Lib "wbtrv32.dll" (ByVal OP, ByVal Pb$, Db As Any, DL As Long, Kb As Any, ByVal Kl, ByVal Kn) As Integer

' define some data types for working with the database files
Type typ_byte4 f1(1 To 4) As ByteEnd TypeRem ***************************************************************************
Rem Btrieve Structures
Type KeySpec
KeyPos As Integer
KeyLen As Integer
KeyFlags As Integer
KeyTot As typ_byte4
KeyType As String * 1
Reserved As String * 5
End Type

Type FileSpec
RecLen As Integer
PageSize As Integer
IndxCnt As Integer
NotUsed As String * 4
FileFlags As Integer
Reserved As String * 2
Allocation As Integer
KeyBuf(0 To 1) As KeySpec
End Type

Type StatFileSpecs
RecLen As Integer
PageSize As Integer
IndexTot As Integer
RecTot As typ_byte4
FileFlags As Integer
Reserved As String * 2
UnusedPages As Integer
KeyBuf(0 To 1) As KeySpec
End Type

Type RecordBuffer
' here you should define the structure of the file that you are reading.. in this example i have 3 'fields, one is an id (int) description and another float type
'change this to your data structure
profID As Integer
profDesc As String * 28
profPrice As Double
End Type

Type VersionBuf
Major As Integer
Minor As Integer
Engine As String * 1
End Type

Type typ_PosBlk
f1(1 To 128) As Byte
End Type

' defining variables with the types we created
Global FileBuf As FileSpec
Global DataBuf As RecordBuffer
Global StatFileBuffer As StatFileSpecs
Global BufLen As Long
Global DBLen As Integer

Rem*******Added to Open multiple files
Public iMaxRuns As Integer
Public bFilesCreated As Boolean

Sub PrintLB(Item As String)
' function for printing data on screen
Dim fTxtFileName As String
BtrFrm32.List1.AddItem Item
Rem Added to write info to file
fTxtFileName = App.Path & "\" & App.EXEName & ".log"
Open fTxtFileName For Append As #1
Print #1, Item Close #1
Rem *************
End Sub

sub readDate()
PrintLB ("Btrieve Sample Test Started")
PrintLB ("")
Rem Local variables needed for conversion from byte to long.
Dim loc_RecTot As Long
Dim h_field1 As String
Dim h_field2 As String
Dim h_field3 As String
Dim h_field4 As String
Dim h_total As String
'Rem **************************
FileName$ = "XFACE.BTR"
PosBlk$ = Space$(128)KeyBuffer$ = Space$(KEY_BUF_LEN)
RemRem ***************** Btrieve Create *********************Rem
Rem ************* SET UP FILE SPECS
FileBuf.RecLen = 34
FileBuf.PageSize = 1024
FileBuf.IndxCnt = 2
FileBuf.FileFlags = 0
''Rem ************* SET UP KEY SPECS
FileBuf.KeyBuf(0).KeyPos = 1
FileBuf.KeyBuf(0).KeyLen = 8
FileBuf.KeyBuf(0).KeyFlags = EXTTYPE + MODIFIABLE
FileBuf.KeyBuf(0).KeyType = Chr$(BFLOAT)
FileBuf.KeyBuf(1).KeyPos = 9
FileBuf.KeyBuf(1).KeyLen = 26
FileBuf.KeyBuf(1).KeyFlags = EXTTYPE + MODIFIABLE + DUP
FileBuf.KeyBuf(1).KeyType = Chr$(BSTRING)

'Open File
KeyBufLen = KEY_BUF_LEN
KeyBuffer$ = txtFileName.txt
BufLen = Len(DataBuf)KeyNum = 0
Status = BTRCALL(BOPEN, PosBlk$, DataBuf, BufLen, ByVal KeyBuffer$, KeyBufLen, KeyNum)
If Status <> 0 Then
Msg$ = "Error Opening file! " + Str$(Status)
PrintLB (Msg$)
GoTo Fini
Else
Msg$ = "File Opened Successfully!" PrintLB (Msg$)
End If

BufLen = Len(DataBuf)
KeyBuffer$ = Space$(255)
KeyBufLen = KEY_BUF_LEN
'Status = BTRCALL(BGETFIRST, PosBlk$, DataBuf, BufLen, ByVal KeyBuffer$, KeyBufLen, 0)
If Status <> 0 Then
Msg$ = "Error on BGETFIRST. " + Str$(Status)
PrintLB (Msg$)
Else
Msg$ = "BGETFIRST okay for : " + DataBuf.profDesc PrintLB (Msg$)
End If
'Get Next Record
BufLen = Len(DataBuf)KeyBuffer$ = Space$(KEY_BUF_LEN)
KeyBufLen = KEY_BUF_LEN
Status = BTRCALL(BGETNEXT, PosBlk$, DataBuf, BufLen, ByVal KeyBuffer$, KeyBufLen, 0)
If Status <> 0 Then
Msg$ = "Error on BGETNEXT. " + Str$(Status)
PrintLB (Msg$)
Else
Msg$ = "BGETFIRST okay for : " + DataBuf.profDesc
PrintLB (Msg$)
End If


end sub

Thursday, November 23, 2006

Using Notify Icon Object

notifyIcon1.Icon = new System.Drawing.Icon(@"c:\1.ico");
notifyIcon1.Visible = true;
notifyIcon1.Text = "Test Notify Icon Demo";
notifyIcon1.BalloonTipTitle = "ByRamiX Product";
notifyIcon1.BalloonTipText = "This Product was programmed ByRamiX";
notifyIcon1.ShowBalloonTip(5000);

Tuesday, October 10, 2006

using the data base class

here we built a simple search engine that uses the batabase class that we built before


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace databasetest
{
///


/// Summary description for WebForm1.
///

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DG1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button BtnSearch;
protected System.Web.UI.WebControls.TextBox txtSearchWord;
db db1;
private void Page_Load(object sender, System.EventArgs e)
{
db1=new db("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("database//freddydb.mdb"));
DG1.DataSource = db1.executeSQL("select * from users");
DG1.DataBind();
db1.closeDBCommand();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.BtnSearch.Click += new System.EventHandler(this.BtnSearch_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void BtnSearch_Click(object sender, System.EventArgs e)
{
try
{
if (txtSearchWord.Text.Trim()!="" )
{
DG1.DataSource = db1.executeSQL("select * from users where username like '"+txtSearchWord.Text+"%' or userfirstName like '"+txtSearchWord.Text+"%' or userLastName like '"+txtSearchWord.Text+"%'");
DG1.DataBind();
db1.closeDBCommand();
}
}
catch (Exception ex)
{
response.write (ex.Message);
}
}
}
}

connecting a database with c# / asp.net

this is the code of database connection and sql executing functions

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

///


/// data base class
///

public class db
{
OleDbConnection gDbConn;
OleDbCommand gDbCmd;
public string error;
public db(string connStr)
{
try
{
gDbCmd = new OleDbCommand();
gDbConn = new OleDbConnection();
gDbConn.ConnectionString = connStr;
error="class built successfully";
}
catch (Exception e)
{
error = "[class constructor] building class faild, error in connecting database error discribe: "+e.Message ;
}
}
public OleDbDataReader executeSQL(String sql)
{
try
{
OleDbDataReader rs ;
gDbConn.Open();
gDbCmd.Connection = gDbConn;
gDbCmd.CommandText = sql;
if (sql.Contains("select") )
rs = gDbCmd.ExecuteReader();
else
{
gDbCmd.ExecuteNonQuery();
rs = null;
}
error = "executeSQL executed successfully";
return rs;
}
catch(Exception e)
{
error = "[execute sql] failed to execute sql statement error discribe:" + e.Message
return null;
}
}
}

an example of using this class here: http://byramix.blogspot.com/2006/10/using-data-base-class.html



Monday, August 21, 2006

Cannot open database requested in login 'databaseName'. Login fails

it happened to me with sql server 2000 and 2005, after restoring the database i couldn't login from asp or asp.net script.
this solution is for sql 2000 but i think it will work also with 2005.
i noticed that after the restore the user that i'm tring to loggin with appears on the logins of the specifice database but the culomn of Login Name is empty. i looked at the same place in the original database and i saw something there... it was lost with the restore! i don't know if it's a bug or what, but i lost few days of fighting with it!
anyway, you need to put the the user name... it's not so easy, i didn't find the way to do it, i had to delete it and add it again.. that also not so simple! so you can delete the login it shouldn;t own nothing... so i had to change all the objects that were owned by this login and then could do it!!
i hope you found this blog before losing too much time on this!! the time that i spent is enough :)
if that helped you so write a commemnt
have a nice programming!!

Discuss Post

Thursday, August 10, 2006

message could not be dilevered to all servers

this error recieved when the email address of the reciever is not legal email address, for example starting with number, or like this format xx@hot..com, or start or have an illegal character like ' ! ?

Thursday, August 03, 2006

Publishing .net WebApplicatuib

if you are tring to publish a .net webApplication, it doesn't matter if it's c# or VB.net you should do the following steps :
1. copy the files tin your projects
you don't need to copy them all, only the aspx, and the congidurations files and very important is to copy the bin directory other wise you'll get theis error message:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Could not load type 'AppName.Global'.

2.Create Virtual Directory
this is a very important step, alot of people loose aloth of time untill they knwo they should do it (at least i did :)
go to the iis, stand on the default webSite (in the websites) and right click and the new virtual director.
if you don;t do this step so you will get the following error message:
An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Friday, July 14, 2006

SELECT random records from a database

asp script:
randomize
sql="select max (ID) as maxid from table"rs.open sql,cn
max=rs("maxid")
rs.close

for i=0 to 100
rndNum=int(rnd()*max)+1
idstr=idstr&rndNum&","
next
idstr=idstr+"0"

sql="select top 25 ID, * from table where ID in ("+idstr+")"
rs.open sql,cn



<% randomize sql="select max (ID) as maxid from table" rs.open sql,cn max=rs("maxid") rs.close for i=0 to 100 rndNum=int(rnd()*max)+1 idstr=idstr&rndNum&"," next idstr=idstr+"0" sql="select top 25 ID, * from table where ID in ("+idstr+")" rs.open sql,cn %>

Sunday, July 02, 2006

asp smartupload subscript out of range

you are using smart upload for uploading a file to the server and you get this ugly erro message "asp smartupload subscript out of range" and i'm sure that you didn't write the uploading script.. well, i spent one whole day with this error, and a got angry when i knew that it's a stupid mistake. just look at the html form the the data sent from, you shoud set the enctype to multipart/form-data

that's all!!

Thursday, May 18, 2006

Request for the permission of type System.Net.WebPermission

your spent too much time on tring tounderstand why your application dons'nt work?? yea tell me about it, security request ...
i'm looking for it two weeks ago.. no one has no idea! until i foud this blog... http://blogs.conchango.com/kenibarwick/archive/2004/11/05/195.aspx
he said it simple! don't put your aplication on shared folder....
i stored my application on a mapped drive on my network!!
so if you did like me just copy the folder to your C drive and it's work properly!
http://www.byramix.com

Tuesday, May 09, 2006

Active Server Pages error ''ASP 0131'' , Disallowed Parent Path , indicate the parent directory

have got a technical problem. Can you explain me the followingstatement, please:
Active Server Pages error ''ASP 0131''
Disallowed Parent Path
/knowledgebase/admin/index.asp, line 1
The Include file ''../ScriptLibrary/incPureUpload.asp'' cannot contain ''..''
toindicate the parent directory.
answer: The problem you described is related to configuration of your web server. In order to avoid this problem please do the following
1. Go to your IIS Manager
2. Right click your web site
3. Choose Properties >
4. Select Home Directory Tab
5. Click ‘Configuration’ button
6. Select App Options Tab
7. Check the Enable Parent Paths
8. Click OK and your new configuration will be saved.
This problem occures specially on new Windows 2003 Server systems as the default setting is not to use parent paths.
Note: Another simple solution is to put your upload script page in your site root. This way it won't need to use parent paths to the ScriptLibrary folder.

SQL Server 2005 SQLExpress error: ...provider: Named Pipes Provider, error 40 - Could not open connection to SQL Server

I got this error immediately after installing VS2005 & SQL Server 2005 Express and trying to establish my first connection using the new server - not a good start at all - and by the looks of it, it's happened to many hundreds, if not thousands, of others too.Generally this error occurs if you cannot connect to the SQL server - as the message says (no sh*t). However, what's not obvious is why...First suggestion is to make sure that you specifiy the instance name as well as the server name (christ knows why, but when MS refer to "Server Name" they really mean "Server Instance Name") eg if your server was named 'bigturnip' then you need to specify 'bigturnip\sqlexpress' (where sqlexpress is the instance name - this one just happens to be the default used by SQL Server 2005 SQLExpress).If that doesn't help, then go into the SQL Server Configuration Manager and make sure you've enabled Named Pipes & TCP (if you're using it) and also go into the Surface Area Configuration tool and make sure you've set it for local &/or remote connection for the connection types you want to use. Then restart the SQL Server (instance) service.
source: http://geekswithblogs.net/timh/archive/2006/01/30/67586.aspx

How to configure SQL Server 2005 to allow remote connections

Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer EditionYou must enable remote connections for each instance of SQL Server 2005 that you want to connect to from a remote computer. To do this, follow these steps:
1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
2. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
3. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply. Note Click OK when you receive the following message:Changes to Connection Settings will not take effect until you restart the Database Engine service.
4. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service.

Discuss Post

this is my first message

well, this is my first message in my technical blog...
check my webpage http://www.byramix.com