Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to know simple code that can be using for connecting to access database in vb.net so that it will work on all client systems after deployment.here is my code
VB
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\USER\Documents\STOCK1.mdb"
 Dim cn As OleDb.OleDbConnection = New OleDb.OleDbConnection(strConnection)
 cn.Open()


The name of my system is USER and the code is working well on it.But on the client system that the name is not USER, it will complain of not finding path of the database. The application is a window based application written in vb.net
Thanks

What I have tried:

VB
Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\USER\Documents\STOCK1.mdb"
 Dim cn As OleDb.OleDbConnection = New OleDb.OleDbConnection(strConnection)
 cn.Open()
Posted
Updated 4-Dec-18 9:26am
v3

You need an install script that modifies the string so that it refers to the correct location. Better still use a generic location that is not tied to a user's actual name. See Where should I store my data?[^].
 
Share this answer
 
Comments
Member 14076569 4-Dec-18 12:28pm    
Please i dont understand you well.The application is a window based application written in vb. Thanks
Richard MacCutchan 4-Dec-18 12:41pm    
"The name of my system is USER and the code is working well on it.But on the client system that the name is not USER"
What more can I say? It is obvious what the issue is. You need to change the string "USER" when you install on any other system. Or do what I suggested and use the advice in OriginalGriff's article.
Member 14076569 5-Dec-18 1:38am    
Thanks.
You could just use the Public Documents folder. Another option is to use environment variables, but you'll need to change your installer/deployment tool as well, unless you create your database on the fly.
 
Share this answer
 
Comments
Member 14076569 5-Dec-18 1:39am    
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900