web.config - store database connection

Discussion in 'ASP.NET / ASP.NET Core' started by nature, Jan 3, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Here's my database connection (right below these questions) and I want to set it up in the web.config but I'm unclear about a few things.
    1) Would I always use localhost (on the server as opposed to my laptop where I test)?
    2) How do I set up an access database here? There's no extension in the example.
    3) The web.config example below has no reference to the actual path - "/_database/. How do I specifiy that?


    OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source="& server.mappath("/_database/whatever.mdb") )

    <appSettings>
    <add key="ConnectionString"
    value="server=localhost;database=Northwind;uid=sa;password=secret;" />
    </appSettings>


    Thanks for your help!
     
  2. Hi Nature,

    In your examples of connectionstrings, both for making an OleDb-connection directly based on the conn-string and as stated in the web.config file, you are referring two kinds of connections, namely the oledb-connection for an access database (Provider=Microsoft.Jet.OLEDB.4.0;data source=x:\xxx\_database\whatever.mdb) and a connectionstring for a SQL-server database (server=localhost;database=Northwind;uid=sa;password=secret;").
    I presume that you want to connect to an access database and that you want to store your connectionstring in the web.config file, so here is the (a) way to go:
    <ul>[*]As you mentioned in your 3rd question : for an access-database, you need a full reference to your database. You could do that by using the Server.Mappath of the directory of your database and assigning it to a label, just to see which is the full reference. Easier is to go to your control panel at DASP, and under your Account information, you'll find the Server Path of the root of you web application [*] Put the connectionstring in a key-value pair in the web.config file.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page