Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have access database in server that will use in web.config website
The database should remain on the server after upload website
I do not know how to path
Please, help me
Posted

Put your connection string in WEB.Config as Simple.V said. then access it using following code

Do you want to read connection string from WEB.Config, right?

C#
public string GetConnectionString(string str)
{
       string conn = ConfigurationManager.ConnectionStrings[str].ConnectionString;
       return conn;
}
 
Share this answer
 
XML
my database is access and have not password

    <add name="AccessConnectionString" connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=?" providername="System.Data.OleDb"></add>
 
Share this answer
 
At the uploaded server you have a connection string for that server..
right then copy that string and add or replace it with your connection string in web.config file like this

1) old web.config looks like this at local system
C#
<connectionstrings>
       <add name="CONNECTION STRING NAME" connectionstring="YOUR OLD CONNECTION STRING" catalog="YOUR" database="" security="True"<br" mode="hold" />            providerName="System.Data.SqlClient" />
   </connectionstrings>


2) Now when you got upload your site and configure your database at remote database server got the connection string from that database copy that to here

C#
<connectionstrings>
       <add name="CONNECTION STRING NAME" connectionstring="YOUR NEW CONNECTION STRING" catalog="YOUR" database="" security="True"<br" mode="hold" />            providerName="System.Data.SqlClient" />
   </connectionstrings>


After doing this you can access your database connection string using this command in your code behind page like this

C#
//import this namespace to your website
using System.Configuration;

//user this statement to get connection string
string con = ConfigurationManager.ConnectionStrings["YOUR CONNECTION STRING NAME"].ConnectionString.ToString();
 
Share this answer
 
web.config file
XML
<connectionStrings>

        <add name="ConnectionString" connectionString="server= .\SQLEXPRESS;database=databasename;Integrated Security=true"/>
    </connectionStrings>
(or)

<add name="ConnectionString" providername="System.Data.SqlClient" connectionstring="server= servername;database=database name;User id= userid;Password=pwd" />
 
Share this answer
 
v2

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