try
{
fileclass fc = new fileclass();
StringCollection sc = fc.fr();
string[] arr = new string[sc.Count];
sc.CopyTo(arr,0);
conclass cc= new conclass();
cc.servername =arr[0];
cc.name =arr[1];
cc.pwd =arr[2];
cc.sp =arr[3];
string s = cc.constring(); MessageBox.Show(cc.con);
SqlConnection mycon = new SqlConnection(string.Format(cc.con));
mycon.Open();
MessageBox.Show("jk"+mycon.State);
mycon.Close();
//this.Hide();
}
catch(Exception ex)
{
//MessageBox.Show("连接数据库失败!!"+mycon.State);
dataconnection dc = new dataconnection();
dc.Show();
dc.Focus();
}
string.format(cc.con)传来的值是一个错误的数据库连接字段,为什么MessageBox.Show("jk"+mycon.State);还显示mycon.state是open的呢.
{
fileclass fc = new fileclass();
StringCollection sc = fc.fr();
string[] arr = new string[sc.Count];
sc.CopyTo(arr,0);
conclass cc= new conclass();
cc.servername =arr[0];
cc.name =arr[1];
cc.pwd =arr[2];
cc.sp =arr[3];
string s = cc.constring(); MessageBox.Show(cc.con);
SqlConnection mycon = new SqlConnection(string.Format(cc.con));
mycon.Open();
MessageBox.Show("jk"+mycon.State);
mycon.Close();
//this.Hide();
}
catch(Exception ex)
{
//MessageBox.Show("连接数据库失败!!"+mycon.State);
dataconnection dc = new dataconnection();
dc.Show();
dc.Focus();
}
string.format(cc.con)传来的值是一个错误的数据库连接字段,为什么MessageBox.Show("jk"+mycon.State);还显示mycon.state是open的呢.
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemdatasqlclientsqlconnectionclassopentopic.asp
怎样才算超出范围,我试了一下,连接字段中有四个值要获取的,是data source、user id、pwd、integrated security,但当没有data source时,验证是否connection就正常,当没有datasource时,就不正常了,为什么?如以下,就出现不正常了。
string.Format("workstation id ={0};data source =({0});user id={1};pwd={2};initial catalog=web;integrated security ={3}",servername,name,pwd,sp);