[英]SQL Connection string Provider name
這是一個通用的問題,我正在構建一個報告生成器:
public ReportGenerator(IReportGeneratorConfig config)
{
Configuration = config;
ImagePaths = new Dictionary<string, string>();
ReportErrors = new StringBuilder();
DatabaseForReportQueries = DatabaseFactory.CreateDatabase(Configuration.DatabaseName);
using (System.Data.Common.DbConnection conn = DatabaseForReportQueries.CreateConnection())
{
//get the connection string for use with the report directly.
ReportConnectionString = conn.ConnectionString + "Provider=SQLOLEDB;";
conn.Close();
}
}
這是我在嘗試運行報告生成按鈕時收到的錯誤消息
Cannot open data source, please check ConnectionString and RecordSource properties.
ConnectionString: Database=Test80;Server=SQL01;uid=mcadmin;pwd=password;Provider=SQLOLEDB;
RecordSource:
除了我在代碼中發送的提供程序之外,所有信息都是完整的。 我不知道如何在Web應用程序中找到提供程序名稱。 這與connectionStrings.config
的providerName
標記不同。 它需要是Provider=something;
連接字符串具有providerName = System.Data.SqlClient
如果使用.NET Provider for SQL Server(System.Data.SqlClient),則無需在連接字符串中指定提供程序名稱。
.NET提供程序的提供程序名稱是基於實現類隱式的,不需要在連接字符串中指定。
不要使用基於COM的OLE DB提供程序(SQLNCLI或SQLOLEDB)或ODBC驅動程序從.NET應用程序訪問SQL Server數據,因為與SqlClient相比,這會導致性能下降。
等效的SqlClient連接字符串是:
Data Source=SQL01;Initial Catalog=Test80;User Id=mcadmin;Password=password;
提供程序名稱取決於您使用的SQL Server Native Client版本。 您可以嘗試Provider=SQLNCLI11
。 有關sql server的可能連接字符串設置的列表,您可以查看ConnectionStrings.com
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.