Connectstring Didn't Work In C#
public static DataSet ParseDatabaseData(string sheetName) { string connectionString = 'Provider=System.Data.SqlClient;Data Source= MHSPC56888_VM1\\SQLEXPRESS;Initial Catalog=xxxxx
Solution 1:
You do not need to specify the Provider in the Connection String.
Try it like this:
publicstatic DataSet ParseDatabaseData(string sheetName)
{
string connectionString = "Data Source= MHSPC56888_VM1\\SQLEXPRESS;Initial Catalog=xxxxxxx;User id=xx;Password=xxxxx;";
Solution 2:
Instead of mentioning the connection string in the individual file itself, you can place the connection string in the web.config or app.config and use the config where ever required.
Sample for web.config place the connection string under the <configuration>, there you can provide the provider name:
<configuration><connectionStrings><addname="ConnString"connectionString="Data Source= MHSPC56888_VM1\\SQLEXPRESS;Initial Catalog=xxxxxxx;User id=xx;Password=xxxxx;"providerName="System.Data.SqlClient" /></connectionStrings></configuration>and inside the file
publicstatic DataSet ParseDatabaseData(string sheetName)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
Note: add using System.Configuration; for the ConfigurationManager.
Post a Comment for "Connectstring Didn't Work In C#"