在web.config或页面本身中设置提供程序名称的位置? [英] Where to set provider name in web.config or page itself ?
本文介绍了在web.config或页面本身中设置提供程序名称的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
If i set provider in sql connection string in web.config file ( providerName="System.Data.SqlClient") then should i also include "using System.Data.SqlClient" in page level coding.
Can i write ado.net code without "using statement" in page by help of provider name specified in sql conn string in web.config?
Please explain.
我尝试过:
我写了providerName =System.Data.SqlClient
我还包括使用System.Data.SqlClient
What I have tried:
I have written providerName="System.Data.SqlClient"
I have also included "using System.Data.SqlClient"
推荐答案
System.Data.SqlClient
提供程序是SQL Server的默认.NET Framework数据提供程序
。
System.Data.OleDb
提供程序是OLE DB的.NET Framework数据提供程序
。
System.Data.Odbc
提供程序是的.NET Framework数据提供程序ODBC
。
System.Data.OracleClien
t提供程序是<$ c $的.NET Framework数据提供程序c> Oracle 。
来源: SqlDataSource.ProviderName属性(System.Web.UI.WebControls) [ ^ ]
你必须在这两个地方指定(连接字符串和代码)
几个例子
SQL Server
TheSystem.Data.SqlClient
provider is the default .NET Framework Data Provider forSQL Server
.
TheSystem.Data.OleDb
provider is the .NET Framework Data Provider forOLE DB
.
TheSystem.Data.Odbc
provider is the .NET Framework Data Provider forODBC
.
TheSystem.Data.OracleClien
t provider is the .NET Framework Data Provider forOracle
.
source: SqlDataSource.ProviderName Property (System.Web.UI.WebControls)[^]
You will have to specify at both the place ( Connection string and code )
Few Examples
SQL Server
using System.Data.SqlClient;
class Program
{
static void Main()
{
string sqlConnString = "Data Source=ServerName;Initial Catalog=DbName;Integrated Security=True"; // for SQL provider name is not mandatory
SqlCommand objSQLCmd = new SqlCommand();
}
}
OLEDB
OLEDB
using System.Data.OleDb;
class Program
{
static void Main()
{
string oleConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D://abc.xls'; Extended Properties= 'Excel 12.0;HDR=Yes;IMEX=1'"; // provider name is mandatory here
OleDbCommand objOleDBExcelCmd = new OleDbCommand();
}
}
这篇关于在web.config或页面本身中设置提供程序名称的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文