Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making a windows application,I have connection string in app.config like this

MSIL
<add name="Assignement1_2008.Properties.Settings.SummonsSoundsv1ConnectionString"
            connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\abc.accdb"
            providerName="System.Data.OleDb" />


The DB abc is located in solution of my project(ie root directory)

I want to use the DB which is located inside Debug folder

How can I Change the connection string of App.config??
Posted
Comments
Syed Salman Raza Zaidi 7-Jun-11 2:18am    
I mean what should be used instead of [DataDirectory|?

You can use this:

MSIL
<add name="Assignement1_2008.Properties.Settings.SummonsSoundsv1ConnectionString"
            connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=.\\abc.accdb"
            providerName="System.Data.OleDb" />


Hope this help :)
 
Share this answer
 
Hi,
there is an entire resource specifically available for connection strings settings.
It can be found: here[^]. There are plenty of examples how you can attach a database to the application, by pointing to a specific file rather than server path.
Regards
 
Share this answer
 
Use directly instead of DataDirectory.

<add name="Assignement1_2008.Properties.Settings.SummonsSoundsv1ConnectionString"
            connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=.\\abc.accdb"
            providerName="System.Data.OleDb" />


This will solve your problem.
 
Share this answer
 
actually when you use |DataDirectory| in database connection string,
it automatically maps the path from where your application is started...

so when you debug or run your program by pressing F5 in Visual Studio, it runs from debug folder path so it will automatically map the database which is copied in debug folder...

That database is copied each and every time you compile the code, if you have default setting for that......

so if you want to map the database which is in your current directory or solution then you have to give static path uptill you developing it.... At last before publishing it, you must replace static path with |DataDirectory|.......

For more detail visit
http://www.connectionstrings.com/

Thanks & Regards,
Punit
 
Share this answer
 

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