Asp.net Sql Connection

Posted by Unknown On Friday, 8 March 2013 0 comments
Asp.net Connection Create

Hi, As per the following way you can create coonection. . .

First of all in your web.config file do the following entry. . .
 in the <configuratin> tab. . .

<connectionStrings>
    <add name="con1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\task_db.mdf;Integrated Security=True;User Instance=True"/>
  </connectionStrings>
 

c:\Documents ... is the path there you have to define your database path.
Now you have to write the following code. . .
 write following line at before page load event means declare global. . .


SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con1"].ToString());

Don't forget to include following namespace...

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

now your connection is create you can use around your form connection with variable con.
 
 

0 comments:

Post a Comment