ASP.NET - without sql source how we can connect with database
Asked By Praveen Mathi on 14-Aug-13 05:12 AM
i want to connect the database in asp.net using webconfig ( without sql source )
give a solution for me
Padhamuthu Mathialagan replied to Praveen Mathi on 14-Aug-13 06:29 AM
Add connection string on Web.Config as follows
<connectionStrings >
<add name="myConnectionString" connectionString="Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Use the classic ADO.NET objects to connect with database and execute Direct query or Stored Procedures
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ToString());
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT * FROM Employees";
cmd.CommandType = CommandType.Text;
cn.Open();