Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


What I have tried:

I have written providerName="System.Data.SqlClient"
I have also included "using System.Data.SqlClient"
Posted
Updated 5-Apr-17 19:37pm
v4
Comments
Bryian Tan 6-Apr-17 1:05am    
web.config. Example.
<connectionStrings>    <add name="MySqlConnection" connectionString="Data Source=Hello;User ID=test;Password=Pass;Initial Catalog=Table1;Integrated Security=True" providerName="System.Data.SqlClient" />      </connectionStrings>


Is the application throwing error message or something?

1 solution

The System.Data.SqlClient provider is the default .NET Framework Data Provider for SQL Server.
The System.Data.OleDb provider is the .NET Framework Data Provider for OLE DB.
The System.Data.Odbc provider is the .NET Framework Data Provider for ODBC.
The System.Data.OracleClient provider is the .NET Framework Data Provider for Oracle.
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
C#
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
C#
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();
    } 
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900