Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
access connectivity string with asp.net
Posted

Add this in web.config file

XML
<connectionStrings>
   <add name="TestConnStr" connectionString="Data Source=bla.bla.global;Initial Catalog=TestDataBaseName;Persist Security Info=True;User ID=UserId;Password=Password" providerName="System.Data.SqlClient" />
 </connectionStrings>


Add this code block into your dataaccess layer

C#
using System.Data.SqlClient;//Use OracleClient if oracle and so on for other types
using System.Configuration;

string StrConn = ConfigurationManager.ConnectionStrings["TestConnStr"].ConnectionString;
sqlConn = new SqlConnection(StrConn);
                SqlCommand comm = new SqlCommand("SP_TestStoredProc", sqlConn);
 comm.CommandType = CommandType.StoredProcedure;
                sqlConn.Open();
                SqlDataReader rdr = comm.ExecuteReader();
                while (rdr.Read())
                {
//Read the data into any object
}
sqlConn.close();
 
Share this answer
 
v3
Try this-
C#
private OleDbConnection con;
public myForm()
{
 con=new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<your datadirectory="" path="">\myAccessFile.accdb;Persist Security=False");
}</your>
 
Share this answer
 
You can find the connections strings from here[^]
 
Share this answer
 
Comments
[no name] 26-Feb-15 2:11am    
Good Answer Mika, 5+

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