borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Add Command not working)Next Topic (msflexgrid with reference to 2 databases) New Topic New Poll Post Reply
AndreaVB Forum : Database : DAO connecting ODBC
Poster Message
jotabe
Level: Big Cheese

Registered: 26-06-2003
Posts: 23

icon DAO connecting ODBC

Hello everybody,

I am with a terrible doubt now : someone can explain to me how can I connect my database with a ODBC connection using a DSN ?

Suppose my database is myDB.mdb (Acess 2000) and VB6) and my DSN is myDSN.  I am doing like this but it isn't going right :

Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase("myDB.mdb", dbDriverNoPrompt, True, "ODBC;DATABASE=myDB;UID=admin;PWD=;DSN=myDSN")

It is displaying the following message :
Run time error 3151 :
ODBC - Connection to "MyDSN" failed.

If someone have any tip I would appreciate it.

My best regards.

Jotabebr

24-02-2005 at 07:40 AM
View Profile Send Email to User Show All Posts ICQ | Quote Reply
~Bean~
Level: VB Guru


Registered: 07-04-2003
Posts: 488
icon Re: DAO connecting ODBC

Use ADO instead of DAO and see the Database downloads section  of this website to find some useful programs

____________________________
Eggheads unite! You have nothing to lose but your yolks.

24-02-2005 at 06:03 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
jotabe
Level: Big Cheese

Registered: 26-06-2003
Posts: 23
icon Re: DAO connecting ODBC

I see, my friend, thanks....but I'd like to know how to connect by DAO.  I have a small project and I like to change small part of the code to access my DSN.

Any tip I'd be thankfull.

Regards.

Jotabebr

25-02-2005 at 03:55 AM
View Profile Send Email to User Show All Posts ICQ | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: DAO connecting ODBC

strConn= "ODBC;DSN=" & DatabaseName & ";UID=" & UserName
& ";PWD=" & UserPassword
set db=OpenDatabase("", False, False, strConn)


____________________________
If you find the answer helpful, please mark this topic as solved.

25-02-2005 at 12:57 PM
View Profile Send Email to User Show All Posts | Quote Reply
jotabe
Level: Big Cheese

Registered: 26-06-2003
Posts: 23
icon Re: DAO connecting ODBC

thanks friend...but it didn't work...I follow your example but it shows the message :

"Run-time error 3423:
You cannot use ODBC to import from, export to or link an external Microsoft Jet or ISAM database table  to your database."

That is my code :
Set db = OpenDatabase("", False, False, "ODBC;DSN=mydsn;UID=admin;PWD=")

If you have some other tip I'd be thankfull.

Regards.

JotaBe

27-02-2005 at 06:01 AM
View Profile Send Email to User Show All Posts ICQ | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: DAO connecting ODBC

Its been a while since I used DAO, but it seems that this message is telling that you cant connect using ODBC and DAO/JET to access database. Is this system DSN? If yes, why dont you use DSN-less connection, which is a recommended way?

____________________________
If you find the answer helpful, please mark this topic as solved.

27-02-2005 at 11:31 PM
View Profile Send Email to User Show All Posts | Quote Reply
jotabe
Level: Big Cheese

Registered: 26-06-2003
Posts: 23
icon Re: DAO connecting ODBC

and would you mind giving to me an example about DSN-less connection, I mean, the sintax of the command ?

thanks a lot.

01-03-2005 at 02:21 AM
View Profile Send Email to User Show All Posts ICQ | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: DAO connecting ODBC

You dont say where the database is stored? If on the another computer, share this database, and just provide a full network path to this database. Like

Set db=opendatabase("\\server\dbPath")


____________________________
If you find the answer helpful, please mark this topic as solved.

01-03-2005 at 04:57 PM
View Profile Send Email to User Show All Posts | Quote Reply
jotabe
Level: Big Cheese

Registered: 26-06-2003
Posts: 23
icon Re: DAO connecting ODBC

OK...thanks...I'll try...but my DB is in my computer, I mean,  "C:\myfolder\mydb.mdb".

my best regards.

02-03-2005 at 08:53 AM
View Profile Send Email to User Show All Posts ICQ | Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: DAO connecting ODBC

Then just change path to your DB... Since db is usually stored in the same folder as application that is using it, you may use App.Path instead

set db=dbengine.opendatabase(app.path & "\mydb.mdb")


____________________________
If you find the answer helpful, please mark this topic as solved.

02-03-2005 at 11:47 AM
View Profile Send Email to User Show All Posts | Quote Reply
jotabe
Level: Big Cheese

Registered: 26-06-2003
Posts: 23
icon Re: DAO connecting ODBC

thanks friend for the tips.

{  } ' s

jotabe

04-03-2005 at 07:09 AM
View Profile Send Email to User Show All Posts ICQ | Quote Reply
AndreaVB Forum : Database : DAO connecting ODBC
Previous Topic (Add Command not working)Next Topic (msflexgrid with reference to 2 databases) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder