the*_*er7 6 c# sql-server database-connection
这更像是一个通用问题,我正在构建一个报告生成器:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我在尝试运行报告生成按钮时收到的错误消息
Cannot open data source, please check ConnectionString and RecordSource properties.
ConnectionString: Database=Test80;Server=SQL01;uid=mcadmin;pwd=password;Provider=SQLOLEDB;
RecordSource:
Run Code Online (Sandbox Code Playgroud)
除了我在代码中发送的提供者之外,所有信息都完好无损。我不知道如何在 Web 应用程序中找出提供者名称。这与 中的providerName标签不同connectionStrings.config。它需要是Provider=something;
连接字符串有一个 providerName = System.Data.SqlClient
如果使用 SQL Server 的 .NET 提供程序 (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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16536 次 |
| 最近记录: |