943,452 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jan 17th, 2003
0

VB: Connect to Access database via ODBC datasource name

Expand Post »
Hi Expert,

I already create a datasource name for my Access database. However, I failed to connect to that database using this code:

Set db = DBEngine.Workspaces(0).OpenDatabase("dbsourcename", ,"DSN=dbsourcename;UID=MyUID;PWD=Mypassw")

Could anyone help me please. Thank.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ChristinaOrchid is offline Offline
5 posts
since Jan 2003
Jan 17th, 2003
0

More info!

What version of VB are you using? And, what is DBEngine declared as?
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jan 19th, 2003
0
Re: VB: Connect to Access database via ODBC datasource name
dont know much about VB @ all but let me ask u a coupla ???...

what db are u trying to access the Access DB from?

does it support ODBC via VB directly, or do you need connection services, managers &/or drivers?

is it necessary to establish a connection authorization from your destination db to your external source (ODBC) db PRIOR to attempting connection?

i come from the Lotus Notes/Domino world, whereby the answers to all of the above is a resounding YES, but i do not know if that is universally true.
Team Colleague
Reputation Points: 186
Solved Threads: 8
Team Member - aka kaynine
aeinstein is offline Offline
643 posts
since May 2002
Jan 19th, 2003
0
Re: VB: Connect to Access database via ODBC datasource name
Just wanna check up on something ...

Personally, I've never connected to a database via ODBC. However, just wanna check:

You say you used the command
Set db = DBEngine.Workspaces(0).OpenDatabase("dbsourcename", ,"DSN=dbsourcename;UID=MyUID;PWD=Mypassw")
to connect to the database. You *DID* replace the items in bold with your own variables, right? Just making sure!

Also ... one more thing ... between dbsourcename and DSN=, you have two commas. Is it supposed to be like that. You use a ; to separate all of the other parameters.

Just a lil syntax check you may wanna look at!
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,645 posts
since Feb 2002
Jan 19th, 2003
1
Re: VB: Connect to Access database via ODBC datasource name
Dani -
Thats wrong :-P. When you use a DSN, you do not need to fill in any other information. The DSN stores everything for you.

Also you seperate connnectionstring items with a ;
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jan 19th, 2003
0
Re: VB: Connect to Access database via ODBC datasource name
What I'm saying is this is the code that ChristinaOrchid used. It doesn't matter whether they're using extraneous info, etc. It might be a syntax error (e.g. they used a comma instead of a semi-colon.)

You just said you don't need to fill in any other info? Well they did (as you can see). Maybe that's the problem?

Just trying to troubleshoot the code THEY used from a syntax error standpoint.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is online now Online
13,645 posts
since Feb 2002
Jan 19th, 2003
1
Re: VB: Connect to Access database via ODBC datasource name
If your using VB.NET or C#.NET the following link is your end-all resource!

http://www.connectionstrings.com/

The following is if you're using VB.NET:

Access
ODBC

Standard Security:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. "Driver={Microsoft Access Driver (*.mdb)};Dbq=\somepath\mydb.mdb;Uid=Admin;Pwd=asdasd;"


Workgroup:
Quote ...
"Driver={Microsoft Access Driver (*.mdb)};Dbq=\somepath\mydb.mdb;SystemDB=\somepath\mydb.mdw;"

OLEDB, OleDbConnection (.NET)


Standard security:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User Id=admin;Password=asdasd;"


Workgroup (system database):
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System Database=system.mdw;","admin", ""


With password:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;","admin", ""

DSN

DSN:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. "DSN=myDsn;Uid=username;Pwd=;"


File DSN:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. "FILEDSN=c:\myData.dsn;Uid=username;Pwd=;"
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002
Jan 20th, 2003
0
Re: VB: Connect to Access database via ODBC datasource name
Hi All,

I will try to describe more clearly my problem:
I am working on my Excel workbook and I create a button trying to connect to Access database or Oracle database that I already created datasource name for those 2 database in ODBC window. However, when I write the code like this:
Set db = DBEngine.Workspaces(0).OpenDatabase("", , , "ODBC;")
this open an ODBC window and let me select a datasource name. When I select an Oracle datasource name, the connection is successful. However, when I select an Access datasource name, I got the message error <<You cannot use ODBC to import from, export to, or link an external Microsoft Jet or ISAM database table to your database. (Error 3423)>>

So, My first question is why I cannot access to Access database??

Second, I trie to test to connect to Oracle/Access database by passing the datasource name as follow:

Set db = DBEngine.Workspaces(0).OpenDatabase("Oracle7", , , "DSN=Oracle7; DBQ=sqn2_mars; UID=MyuserId; PWD=Mypwd"), the effect is the same as if my first example on the top.


Hi Tekmaven,
I did'nt declare my DbEngine. As I know DbEngine is the top level object in the DAO and we can use without declaring it.

Hi aeinstein,
My problem is when I trie to connect to Access database.

Hi cscgal,
I have compied my code and there is no error syntaxe that's why it open the ODBC window and let me select my datasource name.


Thank All for your response, I am looking for all your new response days and days :p)

ChristinaOrchid.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ChristinaOrchid is offline Offline
5 posts
since Jan 2003
Jan 20th, 2003
0
Re: VB: Connect to Access database via ODBC datasource name
I forget to tell that I am using Microsoft Excel 97 .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ChristinaOrchid is offline Offline
5 posts
since Jan 2003
Jan 20th, 2003
0
Re: VB: Connect to Access database via ODBC datasource name
Huh? Are you tring to import data from a table? If you are, just selecet File->Open and change the file type to "Acess Databases." You will recieve a wizard that will automatticly import the data for you!
Moderator
Reputation Points: 322
Solved Threads: 28
The C# Man, Myth, Legend
Tekmaven is offline Offline
914 posts
since Feb 2002

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Skin Vista In VB6
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: showing specific records using vb6 datareport





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC