Solved

VB.NET Database programming question

Posted on 2004-10-12
8
189 Views
Last Modified: 2010-04-23
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
Comment
Question by:gbilios
[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
8 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12285736
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
 

Author Comment

by:gbilios
ID: 12285783
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
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12285841
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
Independent Software Vendors: 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!

 
LVL 9

Expert Comment

by:checoo
ID: 12285901
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
 

Author Comment

by:gbilios
ID: 12285936
I tried that.  I got an error.

The connection objects open method fails
0
 

Author Comment

by:gbilios
ID: 12285952
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
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12285958
what method are you trying config file or Application.StartupPath
Check the path that you have built through a msgbox is it OK ??

0
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 125 total points
ID: 12285976
C:\SCC313\Project4\Students.mdb;" & _
        "Students.mdb;Mode=Share Deny None;" & _

the mdb name is repeating
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

628 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