Saturday, October 25, 2008

How to open sql Connection ?

private string sqlString = "Data Source=Server_Name;Initial Catalog=Database_Name;Integrated Security=SSPI;";

private SqlConnection sqlConn;

if (sqlConn.State != ConnectionState.Closed)
{
sqlConn.Close();
}
sqlConn = new SqlConnection(sqlString);
sqlConn.Open();

/*
Standard Security:

1.
"Data Source=Server_Name;Initial Catalog= Database_Name;UserId=Username;Password=Password;"

2.

"Server=Server_Name;Database=Database_Name;
UserID=Username;Password=Password;Trusted_Connection=False"

Trusted connection:

1. "Data Source=Server_Name;Initial Catalog=Database_Name;Integrated Security=SSPI;"

2."Server=ServerName;Database=Database_Name;
Trusted_Connection=True;"

*/

No comments: