• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

VB.NET Database programming question

This connection string (should) connects to an Access database and its obvious here that it wont connect because VB.NET does not know where the underlying database resides.  What if the application is ported somewhere else like a different folder, would the application still be able to connect to the database.  Its obvious i would need a data source to specify where the underlying database is but what should i do to have the connection string dynamic in a such a way i can port the application without the need of the data source?
 
Dim ConnectionString _
            As String = "Provider=Microsoft.Jet.OLEDB.4.0;Integrated " & _
        "Security=SSPI;Persist Security Info=False;Initial " & _
        "Catalog=Students;Packet Size=4096;Workstation ID=Admin;" & _
        "Use Encryption for Data=False"

0
gbilios
Asked:
gbilios
1 Solution
 
RonaldBiemansCommented:
When you say ported, do you mean the application is installed lets say on a different computer in a different directory ?,

Bye the way you posted your question twice
0
 
gbiliosAuthor Commented:
okay, sorry for submitting the same question twice.

When i said port , i meant what would happen if the application is moved to a different directory or the database is moved to a different directory.

 
0
 
arif_eqbalCommented:
Use Application.StartupPath to get the current Folder i.e. where your EXE is residing, either store the MDB file there or create a relative path

eg
say you store your database in a folder called Database within the folder that holds the exe then

Path=Application.StartupPath & "\YourDataBase.mdb"

then use it in the connection string
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.

 
checooCommented:
rather than hard coding the database path within the application, you can use a app.config file to store the location of the database. Then at runtime you can read that setting and build your connection string accordingly.
0
 
gbiliosAuthor Commented:
I tried that.  I got an error.

The connection objects open method fails
0
 
gbiliosAuthor Commented:
This is the connection string now to connect to an access database.
I tried that code you suggested.  The call to the connection object's open method fails

Dim ConnectionString As String = _
        "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;" & _
        "Jet OLEDB:Database Locking Mode=1;Data Source=C:\SCC313\Project4\Students.mdb;" & _
        "Students.mdb;Mode=Share Deny None;" & _
        "Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:" & _
        "System database=;Jet OLEDB:SFP=False;persist security info=False;" & _
        "Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;" & _
        "Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;" & _
        "Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:" & _
        "Global Bulk Transactions=1"
0
 
arif_eqbalCommented:
what method are you trying config file or Application.StartupPath
Check the path that you have built through a msgbox is it OK ??

0
 
arif_eqbalCommented:
C:\SCC313\Project4\Students.mdb;" & _
        "Students.mdb;Mode=Share Deny None;" & _

the mdb name is repeating
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now