Link to home
Start Free TrialLog in
Avatar of N_K_venkat
N_K_venkat

asked on

How to connect a MDB file thru DAO using only dsn

Dear Friends,
    Here i am having one Mdb file in my server.i want to interact with that database from my client thru DAO.
How to connect a MDB using dsn only and no file path.
Thanks in advance.
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Set database = workspace.OpenDatabase ("DSN=MyDSNName", False, False)



Avatar of Ryan Chong
Hi venkat,

Maybe this link make help too:
http://www.able-consulting.com/ado_conn.htm#ODBCDriverForAccess
Avatar of N_K_venkat
N_K_venkat

ASKER



dear TimCottee,

how to make use of the workspace. it throws some errors
"OBJECT VARIABLE NOT SET". will this support for the database which is in the network???



dear TimCottee,

how to make use of the workspace. it throws some errors
"OBJECT VARIABLE NOT SET". will this support for the database which is in the network???

ASKER CERTIFIED SOLUTION
Avatar of loveneesh_bansal
loveneesh_bansal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
N_K.  Tim wasn't very clear there.  

The error you are receiving is because you have to instatiate the workspace object first.  

Go to the VB Help and lookup "workspace" and also look up "opendatabase" using the Jet engine.

There are examples that are pretty clear on this subject.
but how to use the DSN in the connection string.
open method of the connection object.
Now that sounds much more like ADO than DAO, in ado all you do is:

Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.ConnectionString = "DSN=MyDSN;"
cnn.Open

For a fuller DAO example:


   Dim wrkJet As Workspace
   Dim dbsMyDB As Database

   ' Create Microsoft Jet Workspace object.
   Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

   MsgBox "Opening Database..."
   Set dbsMyDB = wrkJet.OpenDatabase("DSN=MyDSN", False,False)
Dear TimCottee
  will it work for the database in the network also????
Absolutely, the DSN specifies where the database is located.
TimCottee,

boss really a beautiful code but how to use the recordset object to open a table.
will you pls help us on this.
ADO or DAO?
ADO only.
ADO is easy:


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

Dear Friends,
   in the connection object open method is it possible to use the dsn name instead of using file path for the access database using ado.
Dear Friends,
   in the connection object open method is it possible to use the dsn name instead of using file path for the access database using ado.
Dear Friends,
   in the connection object open method is it possible to use the dsn name instead of using file path for the access database using ado.
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20106428.html
https://www.experts-exchange.com/questions/Q.20162135.html
https://www.experts-exchange.com/questions/Q.20164399.html
https://www.experts-exchange.com/questions/Q.20165106.html
https://www.experts-exchange.com/questions/Q.20193420.html
https://www.experts-exchange.com/questions/Q.20262325.html
https://www.experts-exchange.com/questions/Q.20267916.html
https://www.experts-exchange.com/questions/Q.20281031.html
https://www.experts-exchange.com/questions/Q.20285275.html
https://www.experts-exchange.com/questions/Q.20291239.html
https://www.experts-exchange.com/questions/Q.20292191.html
https://www.experts-exchange.com/questions/Q.20292203.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
Thanks for returning and finalizing these questions, however all that I've viewed are "C" grades and no comments from you as to why.  Can you please tell us?  If this was graded in error, I can correct this for you.

More about grading here:
https://www.experts-exchange.com/questions/20310437/Proper-Grading.html

Moondancer - EE Moderator