Access Database Connectionstring in web.config

Hie guys

How do you specify the access database connection string in a web.config file in asp.net 2.0 for deploying on hosting server.Do i have to specify the exact path on the hosting server like i do on the development server.

i used the following and am getting an error
<add name=“AccessConnectionString” connectionString=“~/App_Data/databasename.mdb” providerName=“System.Data.OleDb” />

The error message is like this:
Format of the initialization string does not conform to specification starting at index 0.

thanks

When you have solved this could you post information on how you do the lot?

Store the connection in the web.config
Access the web.config in the code

Reason being I am currently over and over making a connection string in code and want to break the habbit.

I have to say that Ive never used Access as my database but if you goto http://www.connectionstrings.com/ you should be able to find the info that you need.

Tawanda,

I had the same problem and in my search for an answer I found this post. After searching for a long time I found the answer on MSDN, so I thought it would be nice to share it with you:

“If you store the Access .mdb file in the Web site’s App_Data directory, which is recommended for enhanced security, you can specify the location using the syntax |DataDirectory|path. The |DataDirectory| string resolves at run time to the App_Data folder of your Web site.”

The correct syntax for your ConnectionString should be:

<connectionStrings>
<add name=“AccessConnectionString” connectionString=“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|databasename.mdb” providerName=“System.Data.OleDb” />
</connectionStrings>

Tezler,

when you put the above in the web.config file, you can retrieve the connectionstring in code using:

ConfigurationManager.ConnectionStrings.Item(“AccessConnectionString”).ConnectionString

Off course you can use your own name for “AccessConnectionString” and “databasename.mdb”

I hope this answer both of your questions

Many thanks for your reply. Since I downloaded the AccessMembershipProvider this kind of led me to do what you say. Thanks again.

Many thanks for that man.
I cant thank you enough.Anyway God Bless and Happy Programming

Tawanda