Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start a ODBC connection 1

Status
Not open for further replies.

vijip2001

Programmer
Joined
Oct 14, 2003
Messages
61
Location
US
Hi all,

I need my visual basic application to connect to my ODBC connection. I have a ODBC created for my oracle database. How do i do it?
I have the ODBC in a string called DataFile.

DataFile = "ODBC;DSN=scrapdev1;DBQ=scrapdev1;DATABASE="

Please help.

Thanks,
Subha
 
Make a project reference to Microsoft ActiveX Data Objects.

A search for "ADO" should turn up code samples.
 
I am also trying to figure this one out. I am trying to connect to a Firebird DB. I select std exe for the the project type, and then on the Project pull down select "Reference" and then "Microsoft ADO Ext. 2.5 for DDL and Security". Now what?

I tried to locate the dll for Firebird by navigating directly but when I get to the files it says it "cannot add a reference to the specified file".

If I want to connect to Access then I select the Access OLB and then I attach this way. I must be missing something, what is it?


Thanks in advance

Andrew Runals
 
Re: Now what?

You've just created a reference to ADOX. You also need one to Microsoft ActiveX Data Objects 2.5 Library which provides ADO functionality. Then
Code:
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = _
"DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=masterkey;DBNAME=D:\FIREBIRD\examples\TEST.FDB"


Is your Firebird DLL registered? Try

RegSvr32.exe "C:\...\Firebird.Dll"

and then set the reference.
 
OK...start a new project, then add the Reference: "Microsoft ActiveX Data Objects 2.8 Library"

Then, in your code add:

Dim cn as Adodb.connection
Dim rs as adodb.recordset
Dim str as string

Set cn = new adodb.connection
cn.connectionstring = "DSN=Test"

cn.open

Set rs = new adodb.recordset
str = "Select * from tblTest"
rs.open str, cn, (there's 2 recordset parameters here that I can't remember I'm typing this out), adcmdtext
'Work with your recordset

rs.close

cn.close


I typed this from memory, so there may be spelling mistakes. If you're using Visual Studio the quick help will show the proper options. This is an example from VB6. If this doesn't help, let me know. I'll fire up VB and copy one from my old apps.

Leeland
 
For macleod1021's code above, an ODBC (System DSN) connection named 'Test' must exist on your local computer and it must be configured to properly connect to the database that you want to connect to. The database can be anywhere on your network.

This is the connection method/type that takes the least amount of or easiest code. However you are using an extra layer, the ODBC layer, which may cause slower connections and slower program operation. All depends on your network and its traffic.

You can connect directly from ADO to the databse by using connection strings from the site I mentioned earlier in the thread.

I have used both the direct and the ODBC connection. Both work fine.

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top