# Provide Path of database in Web congfig if Database is not in Appdatafolder

• ### Question

• User660836111 posted

Hi,

i am Working in ASp and Asp.net. Database is not in AppDatafolder on Server. I want to give that database path in webconfig to create connnection string . Please guide me how to do this?

Wednesday, May 18, 2016 10:44 AM

• User475983607 posted

its not valid... i want to know exact path on server..... how to pass path of this database

Open IIS and look at the application settings.  Or remote to the server and look.  Or write a quick page that returns the path.

string path = Server.MapPath("~/db/Database.mdb");

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Wednesday, May 18, 2016 11:32 AM
• User753101303 posted

You could likely still use the |DataDirectory| placeholder (if this is what you are using). You can define this placeholder and AFIK you could as well define your own data placeholder:

Make sure to do that for a purpose. AFAIK App_Data prevents to download files placed there (even if mdb files are enabled for download) while in the Db directory, if mdb files are enabled for download then one should be able to download the db from his browser...

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Wednesday, May 18, 2016 11:34 AM
• User1856188736 posted

As per my knowledge,  If you wanted the database to be created in your App_Data folder. You can use the following ConnectionString:

<<gs id="b8899f85-f9df-4849-a856-3e9d6212cb0b" ginger_software_uiphraseguid="59a07055-82f7-4e9a-a34d-6e015ac31267" class="GINGER_SOFTWARE_mark">connectionStrings</gs>>
<<gs id="febd69be-2d9c-47fe-a7bc-9a3466caf0e3" ginger_software_uiphraseguid="e9f87159-8fbd-4a7f-8dc6-43242c3cb846" class="GINGER_SOFTWARE_mark">add</gs> name="ConnectionName" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" providerName="System<gs id="69421ff7-7def-4895-a5a6-50670f9910c4" ginger_software_uiphraseguid="e9f87159-8fbd-4a7f-8dc6-43242c3cb846" class="GINGER_SOFTWARE_mark">.</gs>Data<gs id="71db2558-9871-47c2-9cc8-315c967a1001" ginger_software_uiphraseguid="e9f87159-8fbd-4a7f-8dc6-43242c3cb846" class="GINGER_SOFTWARE_mark">.</gs>SqlClient" />

There is an alternative as well:

<<gs id="6fb1d0d0-9308-47ef-84f7-726529b07289" ginger_software_uiphraseguid="ea165df7-f65e-4c8f-becc-5174464d1f33" class="GINGER_SOFTWARE_mark">add</gs> name="ConnectionName" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MyDatabase;Integrated Security=SSPI;" providerName="System<gs id="fcd18bc3-0115-46d0-9f38-c4ff418f9019" ginger_software_uiphraseguid="ea165df7-f65e-4c8f-becc-5174464d1f33" class="GINGER_SOFTWARE_mark">.</gs>Data<gs id="d8527673-b6a3-450b-a2ae-08c0f5235214" ginger_software_uiphraseguid="ea165df7-f65e-4c8f-becc-5174464d1f33" class="GINGER_SOFTWARE_mark">.</gs>SqlClient"/>

Also, you will see MyDatabase<gs id="e01c3705-8c77-4213-b59b-0069be7ea9bc" ginger_software_uiphraseguid="1f3e92c2-c37a-45f5-b75c-506e09b1fca0" class="GINGER_SOFTWARE_mark">.</gs><gs id="49f91cf4-19ff-407b-b53b-716cd37d0931" ginger_software_uiphraseguid="1f3e92c2-c37a-45f5-b75c-506e09b1fca0" class="GINGER_SOFTWARE_mark">mdf</gs> and<gs id="5676889f-acf8-43a7-a492-d0edc9f875d6" ginger_software_uiphraseguid="1f3e92c2-c37a-45f5-b75c-506e09b1fca0" class="GINGER_SOFTWARE_mark"> .</gs><gs id="e7b3847c-6ad4-416a-959c-334fb2972fcf" ginger_software_uiphraseguid="1f3e92c2-c37a-45f5-b75c-506e09b1fca0" class="GINGER_SOFTWARE_mark">ldf</gs> database files are created in the C:\Users\YourUserName Folder.

I hope this will help you out. Please let me know, what do you think about the resolution I provided. I will be happy to know the feedback. :)

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Thursday, May 19, 2016 12:53 PM

### All replies

• User753101303 posted

Hi,

This is SQL Server? See https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx for a full description of the keywords found in a connection string. In particular when you don't use a path to a db you are using "Data Source" (or Server) which defines the name of the SQL Server and "Initial Catalog" (or Database) which tells the name of the db you want to connect to on that server.

Try http://www.connectionstrings.com/sqlconnection/ for connection strings samples. For example :

If it fails it will be easier to start from the error message you have.

Wednesday, May 18, 2016 10:59 AM
• User-718146471 posted

With web applications, you can put your database file elsewhere but the path has to be a web folder inside IIS. If the application cannot see it, it will not work. For example, on your server you place your database file and log in a folder e:\data that folder has to be a web folder inside your application. The only time a hard drive path works is locally. Does that make sense?

Wednesday, May 18, 2016 11:02 AM
• User660836111 posted

My database is MS Access

Wednesday, May 18, 2016 11:07 AM
• User660836111 posted

Sir how to give path in webconfig File? My new Path is Root:->Db\Database.mdb

<add name="Con" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=~\db\Database.mdb;Persist Security Info=True"/>

Wednesday, May 18, 2016 11:08 AM
• User475983607 posted

The node looks like this,,,

<add name="Connection"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source='C:\path\to\the\MS Access\file\db.mdb'" />

I'm not sure if the "~" is valid since this is a file path not a virtual folder.

Wednesday, May 18, 2016 11:19 AM
• User660836111 posted

its not valid... i want to know exact path on server..... how to pass path of this database

Wednesday, May 18, 2016 11:24 AM
• User475983607 posted

its not valid... i want to know exact path on server..... how to pass path of this database

Open IIS and look at the application settings.  Or remote to the server and look.  Or write a quick page that returns the path.

string path = Server.MapPath("~/db/Database.mdb");

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Wednesday, May 18, 2016 11:32 AM
• User753101303 posted

You could likely still use the |DataDirectory| placeholder (if this is what you are using). You can define this placeholder and AFIK you could as well define your own data placeholder:

Make sure to do that for a purpose. AFAIK App_Data prevents to download files placed there (even if mdb files are enabled for download) while in the Db directory, if mdb files are enabled for download then one should be able to download the db from his browser...

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Wednesday, May 18, 2016 11:34 AM
• User1856188736 posted

As per my knowledge,  If you wanted the database to be created in your App_Data folder. You can use the following ConnectionString:

<<gs id="b8899f85-f9df-4849-a856-3e9d6212cb0b" ginger_software_uiphraseguid="59a07055-82f7-4e9a-a34d-6e015ac31267" class="GINGER_SOFTWARE_mark">connectionStrings</gs>>
<<gs id="febd69be-2d9c-47fe-a7bc-9a3466caf0e3" ginger_software_uiphraseguid="e9f87159-8fbd-4a7f-8dc6-43242c3cb846" class="GINGER_SOFTWARE_mark">add</gs> name="ConnectionName" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" providerName="System<gs id="69421ff7-7def-4895-a5a6-50670f9910c4" ginger_software_uiphraseguid="e9f87159-8fbd-4a7f-8dc6-43242c3cb846" class="GINGER_SOFTWARE_mark">.</gs>Data<gs id="71db2558-9871-47c2-9cc8-315c967a1001" ginger_software_uiphraseguid="e9f87159-8fbd-4a7f-8dc6-43242c3cb846" class="GINGER_SOFTWARE_mark">.</gs>SqlClient" />

There is an alternative as well:

<<gs id="6fb1d0d0-9308-47ef-84f7-726529b07289" ginger_software_uiphraseguid="ea165df7-f65e-4c8f-becc-5174464d1f33" class="GINGER_SOFTWARE_mark">add</gs> name="ConnectionName" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MyDatabase;Integrated Security=SSPI;" providerName="System<gs id="fcd18bc3-0115-46d0-9f38-c4ff418f9019" ginger_software_uiphraseguid="ea165df7-f65e-4c8f-becc-5174464d1f33" class="GINGER_SOFTWARE_mark">.</gs>Data<gs id="d8527673-b6a3-450b-a2ae-08c0f5235214" ginger_software_uiphraseguid="ea165df7-f65e-4c8f-becc-5174464d1f33" class="GINGER_SOFTWARE_mark">.</gs>SqlClient"/>

Also, you will see MyDatabase<gs id="e01c3705-8c77-4213-b59b-0069be7ea9bc" ginger_software_uiphraseguid="1f3e92c2-c37a-45f5-b75c-506e09b1fca0" class="GINGER_SOFTWARE_mark">.</gs><gs id="49f91cf4-19ff-407b-b53b-716cd37d0931" ginger_software_uiphraseguid="1f3e92c2-c37a-45f5-b75c-506e09b1fca0" class="GINGER_SOFTWARE_mark">mdf</gs> and<gs id="5676889f-acf8-43a7-a492-d0edc9f875d6" ginger_software_uiphraseguid="1f3e92c2-c37a-45f5-b75c-506e09b1fca0" class="GINGER_SOFTWARE_mark"> .</gs><gs id="e7b3847c-6ad4-416a-959c-334fb2972fcf" ginger_software_uiphraseguid="1f3e92c2-c37a-45f5-b75c-506e09b1fca0" class="GINGER_SOFTWARE_mark">ldf</gs> database files are created in the C:\Users\YourUserName Folder.

I hope this will help you out. Please let me know, what do you think about the resolution I provided. I will be happy to know the feedback. :)

• Marked as answer by Thursday, October 7, 2021 12:00 AM
Thursday, May 19, 2016 12:53 PM