1,105,581 Community Members

Is it possible to allow the user to specify the Connection String

Member Avatar
maurice91
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

I have a Vb.Net solution that contains several forms that read/write to an MS Access database.

My problem:

When I copy my Vb.Net solution and Access database to a new computer, the data source connection string needs to be changed. Currently the data sources wizard sets the connection string.

Is it possible to allow the user specify the connection string of the dataset or is there a different, better solution available?

Thanks for your time.

Member Avatar
Reverend Jim
Noli mentula
5,464 posts since Aug 2010
Reputation Points: 770 [?]
Q&As Helped to Solve: 654 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

The connection string will have parameters like

dbq (the file name)
uid (user ID)
pwd (password)

You can prompt the user for them the first time then save the resulting connection string (or the individual parameters) in Settings variables to preseve them between sessions. The actual connections string will also depend on whether you are using OLEDB, SQL, ADO, etc for access. For example, ADO might be

Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\temp\my.db;Uid=John;Pwd=Joshua;
Member Avatar
tinstaafl
Postaholic
2,014 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 403 [?]
Skill Endorsements: 36 [?]
 
0
 

Probably a form, maybe a dialog form, with several textboxes lablelled with the various pieces of information you'll need to make the connection string(i.e. server, login, name of the database, etc.). Of course you'll have to validate each piece of info to make sure it's in the right format.

Member Avatar
maurice91
Newbie Poster
5 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for the responses.

This is my connection string:

Provider=Microsoft.ACE.OLEDB.12.0;
Data Source="C:\Users\Maurice\Documents\Visual Studio 2010\Projects\vbass3\vbass3.accdb"

I don't need a username/password for my database.

Where would I write the code that prompts the user to browse to the Data Source?

Member Avatar
Reverend Jim
Noli mentula
5,464 posts since Aug 2010
Reputation Points: 770 [?]
Q&As Helped to Solve: 654 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
1
 

You could just use a file browser control on form load and ask the user to select the appropriate *.accdb file. Of course, you'd have to ensure that the selected file is one that actually contains the correct tables. Remember to set the file mask to restrict the selection to accdb files.

Question Answered as of 1 Year Ago by Reverend Jim and tinstaafl
Member Avatar
tinstaafl
Postaholic
2,014 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 403 [?]
Skill Endorsements: 36 [?]
 
0
 

oops didn't realize it was solved lol

Member Avatar
Lethugs
Junior Poster
131 posts since Nov 2012
Reputation Points: 8 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

how about my case related to this?

Click Here

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: