使用asp.net访问连接字符串
问题描述:
使用asp.net访问连接字符串
access connectivity string with asp.net
答
您可以从这里 [ ^ ]
试试这个 -
Try this-
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>
在web.config文件中添加这个
Add this in web.config file
<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
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();
>