Connection String in the .net for Ms Access using System.Data.Odbc; ------------------------------------------ using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.Open(); Connection String in the .net for MSSQL Server The best practice to define your connection string in the connection.config file otherwise you can directly do the code in web.config. Connection string in .NET 2.0 <appSettings> To read the connection string from code, use the ConfigurationSettings class. Connection string in .NET 3.5 and above connection <connectionStrings> To read the connection string into your code, use the ConfigurationSettings class.
OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "Dsn=DsnName";
conn.Open();
conn.ConnectionString =
"Driver={Microsoft Access Driver (*.mdb)};" +
"Dbq=c:\myPath\myDb.mdb;" +
"Uid=Admin;Pwd=;";
<add key="myConnectionString" value="server=localhost or websitename or serverIP ;database=myDb;uid=myUser;password=myPass;" />
</appSettings>
string connStr = ConfigurationSettings.AppSettings("myConnectionString");
<add name="myConnectionString" connectionString="server=localhost or websitename or serverIP;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings>
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;