-1

I am creating windows form application. This application will use Microsoft Access Database to record the details. I want to know how can i provide connection string to that database if i create that installable setup file.

Currently i am using like this.

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Amrit\\Desktop\\Database.accdb ;Persist Security Info=False;";

How can i add universal connection string so that it will work on any computer when installed.

Amrit Sharma
  • 1,906
  • 8
  • 45
  • 75
  • Your program will have to know where the access database file is stored on the user's PC, and provide the path to that file as the Data Source in the string. – mbeckish Feb 12 '13 at 14:37
  • Change the path to the user's roaming application data and don't hardcode it. Look up the relevant path and insert it into your connection string at runtime. This should be done from the application, not the setup IMHO. – John Willemse Feb 12 '13 at 14:39
  • What do you mean "universal" connection string. You have to install software require for the provider to even work. What you have already IS a universal connection string. – Security Hound Feb 12 '13 at 14:40

2 Answers2

1

It really does depend on where you intend to install the file. if it is going to be in a consistent location you could use something like (obviously changing Environment.SpecialFolder as required):

var source = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Database.accdb);

Then build up your connection string using source.

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50
0

Use it as

string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Directory.GetCurrentDirectory().ToString() +"Database.accdb ;Persist Security Info=False;"

So it will point to current application path + file name

user13657
  • 745
  • 3
  • 17
  • 36