SqlConnection SconnStr=new SqlConnection(@"Server=local;Integrated Security=SSPI;Database=finace");
if(SconnStr.State.ToString() == "Closed")
{
try
{
SconnStr.Open();
}
catch(Exception ex)
{
if (ex!=null)
MessageBox .Show (ex.ToString ());
}
}
运行这段程序提示:sql server不存在或拒绝访问
但我已经启动了,并且有对的用户名和密码
if(SconnStr.State.ToString() == "Closed")
{
try
{
SconnStr.Open();
}
catch(Exception ex)
{
if (ex!=null)
MessageBox .Show (ex.ToString ());
}
}
运行这段程序提示:sql server不存在或拒绝访问
但我已经启动了,并且有对的用户名和密码
(比較生成的sqlConnection的ConnectionString)
改成
SqlConnection SconnStr=new SqlConnection(@"Server=local;Integrated Security=SSPI;Database=finace;UID=sa;PWD=;");
试试,前提是确定没有密码,另外,Server=local;一句也最好改成Server=.