Thursday, 8 June 2017

How to create a connection string in c# in godaddy

C# SQL Server Connection

In web.config under <configuration>  create global connection like below

      <add name="myconnection" connectionString="Data Source=Server IP Address; Initial Catalog=Database Name; User ID=Database User ID; Password='Database Password';"
         providerName="System.Data.SqlClient" />


Use the connection string into your .cs page as follow:

using System.Data.SqlClient;
using System.Web.Configuration;

 SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myconnection"].ConnectionString);

The "name" which you gave in web.config file and name which you used in connection string must be same(like "myconnection" in this solution.)