-
DSN free code
Hi,
I have a small application in VB which writes some information onto Microsoft Access database tables. For this to happen, I have created a DSN referring the corresponding .mdb file.
To run my application on some other machine I need to create a DSN over there. This is going to be a tedious job.
Can anyone suggest me a method wherein I can access the database tables without the use of a DSN.
Any help/ideas in this regard would be highly appreciated.
Regards
Cufit
-
If you can map drive
And if you can have your access mdb in a shared folder,
and if clients may have rights to read wirte there, then you could
map on each client the folder where the mdb is and use
a built connection string that might be all te same for each client
Or you could have a component on server (=machine where
access is) that retrieve recordsets or write or update or delete,
and have clients referencing and using that component.
If mdb is on a machine like win2k or greater, you could take
advantage of Com+.
If not, you might have to fight with Dcom, in wich case you
might prefer the Dns strategy....
-
cufit99,
You can access the database without the DSN, this is called a DSN-less connection. Below is a sample connection string for Access database using ADO Jet provider.
Code:
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=<the mdb path here>"
-
Hi,
Thank you both Cimperiali and Thread1.
My application mostly runs over a private network, so having the mdb file in a shared folder is not feasible.
So, I tried to use the DSN less connection and it really worked well. Now I'm trying out ways to create an mdb file with the required tables programatically.
Thank You for your timely help.....
Regards,
Cufit
-
DSN free code
Why don't you try to change DSN from VB? All you have to do is to modify something in registry.
-
Hi
This thread came in a search I did.
My problem is after I make the DSN-less connection to the Access Database, I get a recordset with -1 RecordCount.
Here's the Code:
Code:
cnPhase1.Open GetConnectionString(strPhase1DB)
rsPhase1.LockType = adLockOptimistic
rsPhase1.ActiveConnection = cnPhase1
rsPhase1.Source = "Phase1"
rsPhase1.Open
...
Code:
Private Function GetConnectionString(filename As String) As String
GetConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & filename
End Function
I don't get any errors, just a -1 as rsPhase1.RecordCount.
When I open the Database with MS Access, go into the table "Phase1", I see 2 existing records.
What could be the problem?
Thanks in advanced.
-
use cursorlocation = adUseClient for your connection object before opening it
-
..and for CursorLocation = adUseServer (default), try to use cursor that supports the bookmarking (method Supports(adBookMark)) - Keyset and Static (adOpenKeyset and adOpenStatic) in the CursorType property of the recordset obj.
-
Try MoveLast before RecordCount.
Code should be also secured with checking BOF and EOF properties.
aki999