?
Solved

would like to connect to an mdb file using DSN only

Posted on 2001-08-08
13
Medium Priority
?
177 Views
Last Modified: 2006-11-17
hello everyone,
i have a database e:\user\sample.mdb,
i want to interact with this mdb thru adodb using
DSN <b>connection only</b>.

some people gave some codes but those were not working fine.

0
Comment
Question by:karthikdd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 6363917
Assuming you have the DSN set up correctly all you should need to do is this:

Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DSN=MyDSN;"
cnn.Open

If you are using access 97, you could use provider string OLEDB.3.51 instead, 4.0 is required for access 2000.
0
 

Author Comment

by:karthikdd
ID: 6363931
what is the purpose of the command cnn.open
will it open the tables in it.
how to open the tables in this.
let me know plz
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6363946
All that the cnn (Connection Object) does is open a connection to the database itself, to open a recordset against a table use the following:

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.ConnectionString = "DSN=MyDSN;"
cnn.Open
rst.Open "MyTable",cnn,adOpenStatic,adLockOptimistic,adCmdTable
With rst
 .MoveFirst
 Do
   Msgbox .Fields("MyField").Value
   .MoveNext
 Loop Until .Eof
End With
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing

This method opens an entire table, if you omit the last parameter (adCmdTable) you can also use any legitimate SQL statement in the first parameter:

rst.Open "Select * From MyTable Where MyField = 'Hello'",cnn,adOpenStatic,adLockOptimistic,

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:karthikdd
ID: 6363966
got an error like this

ADO could not find the specific provider
in the line

cnn.open
0
 

Author Comment

by:karthikdd
ID: 6363999
we got the answer.

but in the cnn.open method we used the following code below.

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\user\sample.mdb;Persist Security Info=False"

but actually is it possible to use the DSN name there instead of the DataSource.

can anyone help in this.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6364001
Use
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DSN=MyDSN;"

For Access 2000 or

cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;DSN=MyDSN;"

For access 97
0
 

Author Comment

by:karthikdd
ID: 6364038
the error is could not find instalable 'ISAM'
is the error which we get now.

where r u working??
you seem to be really knowledgable person that why??
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6364073
karthikdd, I am based in the UK.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6364102
This does seem to be a problem, as I don't use DSNs as a rule, I haven't bothered much with this in the past. Generally speaking the method you found, specifying the database path explicitly in the connection string is a much better method. In the long run it gives you greater flexibility as you don't have to setup DSN entries for every machine on which the application is installed.
0
 

Expert Comment

by:ifthenelse
ID: 6364309
hai try this



dim cn as adodb.connection

set cn = new adodb.connection

cn.open("dsnname")


thats it....

For table to be opened

Dim rec as recordset
set rec = new adodb.recordset

open table
rec.open"select * from tablename",cn


hope this would help you..

first you should create a dsn ...
 goto start menu
click on run
type odbcad32
now now click on add
... type a dsn name
...click on select
...click on the database name
... on our left side the database name would be highlighted
....click on that other wise it would not accept.
...ok
...ok
thats it ...

happy programming
0
 

Expert Comment

by:ifthenelse
ID: 6367649
is your problem solved ....
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7199834
Hi karthikdd,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

karthikdd, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7213395
Per recommendation, points refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question