step1:
Add the SQL Client namespace i.e,
using System.Data.SqlClient;
Step2:
Create a SqlConnection and specifying the connection string
Add the SQL Client namespace i.e,
using System.Data.SqlClient;
Step2:
Create a SqlConnection and specifying the connection string
SqlConnection newConn = new SqlConnection(
"user id=usrname;" +
"user id=usrname;" +
"password=password;" +
"server=serverurl;" +
"server=serverurl;" +
"Trusted_Connection=yes;" +
"database=database; " +
"connection timeout=30");
Step3:
This is the last step to get connected
SqlConnection.Open()
try
{
newConn.Open();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
SqlConnection.Open()does not return an error but throws an exception so must be kept in a try/catch brace. rather than having the program explode in front of the user.
my blog is abt Sql Connection
ReplyDeletegreat codes checkout my blog at
ReplyDeletehttp://www.definingwords.blogspot.com/2012/10/being-your-self.html
feel free to leave a comment