VB connection to access

Status
Not open for further replies.

deepak.krishnan

In the zone
Hello friends
I made a project in which I have to connect the concerned file to a database. But when I transferred it a CD and tried to work with it in another computer, I got the message saying that the database was not found in the spcified drive.The projesct was converted to *.exe in VB itself.Is there any way to code the program to connect to the database by searching the computer and finding out where it is located.Please help urgently.
 

RCuber

The Mighty Unkel!!!
Staff member
How do you access the database? and Where is the database stored? and also give the string which connects the program to the database then i could help.
 
OP
deepak.krishnan

deepak.krishnan

In the zone
well I made the database using the option in VB and the database is stored in:
f:\School Projects\open\idpro.mdb

idpro.mdb is the database name

There is a program which can store the information your want in the database.
 

RCuber

The Mighty Unkel!!!
Staff member
In the program find the string locating the database . If the path is as u said "f:\School Projects\open\idpro.mdb" then change it to "\open\idpro.mdb" and make sure the file is in that directory.. What this does is irrespective of the drive the software is installed the program looks for the file in "\open" directory. Take for example

the directory is some thing like this when u install the software.

d:\School Project --> the application directory of ur project where your exe file is there.

make another directory "open"

so that it looks like this
d:\School Project\open --> this is where the database will be stored locally.


and now do what i said in the code . This must work.

Its been more that three years since i last programmed in VB . I hope this thing works. Test it and let me know.
Charan
 

it_waaznt_me

Coming back to life ..
Creeate string called strPath and Database location

Code:
Dim strPath as String
Dim strDatabaseLocation as String
strPath = App.Path
strDatabaseLocation = strPath & "\idpro.mdb"

Now use strDatabaseLocation in the connection string for your database object.
 

tuxfan

Technomancer
What it_waaznt_me suggested will work if the .exe and the .mdb are in the same location (app.path). Actually, thats surely is the most advisable way to store the database.

Never give an absolute path in your code (like "C:\Program Files\MyApp\mydb.mdb"). If the software is installed in some other location, it won't work. So give a relative path and use app.path
 

nikdesign4u

Broken In
try following...

Dim AdoFa As New ADODB.Connection

Dim ConnectString As String

ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\open\idpro.mdb ; Persist Security Info=False"

With AdoFa
.ConnectionString = ConnectString
.ConnectionTimeout = 10
.CursorLocation = adUseClient
.Open
End With
 
OP
deepak.krishnan

deepak.krishnan

In the zone
nikdesign4u said:
try following...

Dim AdoFa As New ADODB.Connection

Dim ConnectString As String

ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\open\idpro.mdb ; Persist Security Info=False"

With AdoFa
.ConnectionString = ConnectString
.ConnectionTimeout = 10
.CursorLocation = adUseClient
.Open
End With

I tried it by copying it into the code window of data object.But still the error appears that idpro.mdb could not be found.Where should I use the above code provided.(should it be in the code window of data object itself?)
 
OP
deepak.krishnan

deepak.krishnan

In the zone
it_waaznt_me said:
Creeate string called strPath and Database location

Code:
Dim strPath as String
Dim strDatabaseLocation as String
strPath = App.Path
strDatabaseLocation = strPath & "\idpro.mdb"

Now use strDatabaseLocation in the connection string for your database object.

I did not understand your code.Can you please elaborate that to me.I pasted your code in the general declerations window.But it dosent work.
An error appears saying that: "invalid outside procedure" and it highlights that App.path in your code.
 

it_waaznt_me

Coming back to life ..
Hmm.. First tell me how do you access the database ...? Are you using ADO ? or are you using code based as nikdesign suggested.

Waise nikdesign's method should work. Only change the :
Code:
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\open\idpro.mdb Persist Security Info=False" 

to

ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\idpro.mdb Persist Security Info=False"
 
Status
Not open for further replies.
Top Bottom