使用asp.net访问连接字符串 [英] access connectivity string with asp.net

查看:101
本文介绍了使用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();

这篇关于使用asp.net访问连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆