Connecting to .DBs Database from Visual Basic

MiRRoR
MiRRoR used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you can connect to .db's file using odbc connections. Make an odbc connection which points to the directory where the .db file is existing. then in your Visual Basic Program do the following

dim Cn as new adodb.connection
dim Rs as new adodb.recordset

cn.open "dsn=MyDataDsn"
Rs.open "select * from DataFileName ",cn

while opening a recordset give the filename from which you would like to retrieve data from.


Regards

JBS
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.

Commented:
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>"

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
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>"

Author

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial