Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Connection string Provider name

This is more of a generic question , I am building a report Generator :

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();
    }
}

This is the error message I'm getting when trying to run the report generation button

Cannot open data source, please check ConnectionString and RecordSource properties. 
ConnectionString:   Database=Test80;Server=SQL01;uid=mcadmin;pwd=password;Provider=SQLOLEDB; 
RecordSource: 

All the information are intact apart from the Provider that I'm sending in my code. I don't know how to find out the provider name in the web app. This is not the same as the providerName tag in connectionStrings.config. It needs to be Provider=something;

The connection string has a providerName = System.Data.SqlClient

like image 391
thestralFeather7 Avatar asked May 02 '15 20:05

thestralFeather7


People also ask

What is the provider name for SQL connection string?

The System. Data. SqlClient provider is the default . NET Framework Data Provider for SQL Server.

How do I find my ODBC provider name?

On the Drivers tab, you can find a list of all the ODBC drivers installed on your computer. (The names of some of the drivers may be listed in multiple languages.)

What is a provider in SQL?

The . NET Framework Data Provider for SQL Server (SqlClient) uses its own protocol to communicate with SQL Server. It is lightweight and performs well because it is optimized to access a SQL Server directly without adding an OLE DB or Open Database Connectivity (ODBC) layer.

How do I find my connection string name?

Right-click on your connection and select "Properties". You will get the Properties window for your connection. Find the "Connection String" property and select the "connection string". So now your connection string is in your hands; you can use it anywhere you want.


2 Answers

You don't need to specify the provider name in the connection string if you are using the .NET Provider for SQL Server (System.Data.SqlClient).

Provider names for .NET providers are implicit based on the implementing class and do not need to be specified in the connection string.

Don't use a COM-based OLE DB provider (SQLNCLI or SQLOLEDB) or ODBC driver for SQL Server data access from .NET applications as that incurs a performance penalty compared with SqlClient.

The equivalent SqlClient connection string is:

Data Source=SQL01;Initial Catalog=Test80;User Id=mcadmin;Password=password;
like image 100
Dan Guzman Avatar answered Sep 21 '22 05:09

Dan Guzman


The Provider Name depends on the SQL Server Native Client version you are using. You might try Provider=SQLNCLI11. For a list of possible connection string settings for sql server you can take a look at ConnectionStrings.com

like image 39
Peter Schneider Avatar answered Sep 21 '22 05:09

Peter Schneider