Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL providerName in web.config

We are using ASP.NET (Framework 2) and setting database connection strings (SQL2005) in web.config.

We are currently using "providerName=SqlServer".

All our data accesses are done using System.Data.SqlClient - should we therefore change to providerName=System.Data.SqlClient? I find many examples of this providerName on the web, but very little explaining what providerName=SqlServer actually means.

Is there a difference? I'm worried that the providerName we currently specify is actually referencing a legacy (and maybe slower) client, or is there an even more efficient client than SqlClient for use with ASP.NET?

like image 693
Ali Avatar asked Mar 30 '11 09:03

Ali


People also ask

What is connection string providerName?

The providerName attribute is used to set the name of the .NET Framework data provider that the DataSource control uses to connect to an underlying data source. If no provider is set, the default is the ADO.NET provider for Microsoft SQL Server.

Where are connectionStrings in web config?

Connection strings go inside a <connectionStrings> element. The traditional place to put <connectionStrings> seems to be immediately before <appSettings> but its precise location shouldn't matter.

What is providerName system data SqlClient?

Data. SqlClient as the value of the providerName attribute. It is the . NET Framework Data Provider you are using.


2 Answers

System.Data.SqlClient is the .NET Framework Data Provider for SQL Server. ie .NET library for SQL Server.

I don't know where providerName=SqlServer comes from. Could you be getting this confused with the provider keyword in your connection string? (I know I was :) )

In the web.config you should have the System.Data.SqlClient as the value of the providerName attribute. It is the .NET Framework Data Provider you are using.

<connectionStrings>    <add        name="LocalSqlServer"        connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"        providerName="System.Data.SqlClient"    /> </connectionStrings> 

See http://msdn.microsoft.com/en-US/library/htw9h4z3(v=VS.80).aspx

like image 106
Adrian Toman Avatar answered Oct 19 '22 04:10

Adrian Toman


 WebConfigurationManager.ConnectionStrings["YourConnectionString"].ProviderName; 
like image 24
Paul Volkov Avatar answered Oct 19 '22 05:10

Paul Volkov