Link to home
Start Free TrialLog in
Avatar of MiRRoR
MiRRoR

asked on

Connecting to .DBs Database from Visual Basic

I need to find out how it is possible to ,
Through Visual Basic, Connect to a database file eg. Data.DBs!

Please could anyone help me! ASAP

Nice points are up for grabs!

MiRRoR
ASKER CERTIFIED SOLUTION
Avatar of jayeshshah
jayeshshah
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of inthedark
Here is a quick way.....create a new text file, rename the file MyData.udl, then double click on the file.  Click on the provider tab, select the provider required, Access/Oracle/SQL Server for example then click next, depending on your database you may be asked other details, like username/password to complete the process.  You will also get a "Test Connection" button.  When the test is complete you can open the file with notepad the connection string is below the *.

Paste the connection string into your code like:

Set CN=New ADODB.Conection
CN.ConnectionString = "......."
CN.Open

Now you can use the Connection to open your database.
Avatar of ks2000
ks2000

this is from SQLServer:

dim con as new adodb.connection
con.open "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=<login>;password=<pwd>;Initial Catalog=<dbname>;Data Source=<ServerName>"

this is for SQLServer:

dim con as new adodb.connection
con.open "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=<login>;password=<pwd>;Initial Catalog=<dbname>;Data Source=<ServerName>"

Avatar of MiRRoR

ASKER

DBF Files
Try the method to open the connection

str_Connection = "Provider=MSDASQL.1;Driver=Microsoft Visual FoxPro Driver;UID=;PWD=;SourceDB=" & Directory Path where the dbf files exists  & ";SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"

Cn.Open str_Connection
Cn.DefaultDatabase = Directory Path where the dbf files exists


''  selecting records from the dbf file
rs.open "select * from dbffilename "

this will definately work.

Regards
JBS