I have a problem. I wrote this method for opening sql connection. But it did not work.
why didn’t this work.
public SqlConnection connection( )
{
string DBName = ConfigurationManager.AppSettings["DBName"].ToString();
string ServerName = ConfigurationManager.AppSettings["ServerName"].ToString();
string UserId = ConfigurationManager.AppSettings["UserId"].ToString();
string DBPassword = ConfigurationManager.AppSettings["DBPassword"].ToString();
EMVTool.OSSPwdProcessor PwdPass = new EMVTool.OSSPwdProcessor();
String sClearPwd = "";
if (DBPassword.Length > 40)
sClearPwd = PwdPass.DecryptPwd(DBPassword);
else
sClearPwd = DBPassword;
string ConnectionString = "Server=" + ServerName + ";Database =" + DBName + ";UID =" + UserId + ";PWD =" + sClearPwd + ";MultipleActiveResultSets=True;";
SqlConnection connect = new SqlConnection(ConnectionString);
return connect;
}
and i am calling the method like that for opening sql connection.
connection().Open();
It didn’t work because you opened something but then used different instance afterwards.
To make it work, assign the function return value to local variable: