一、不同字符串定义方式
1)直接定义字符串并连接
`static SqlConnection conn;//定义连接对象
public static SqlConnection Connection//连接对象的属性
{
get
{
if (conn == null)
{
string connstr = "Data Source = (local); uid=sa;pwd=12345678;Initial Catalog =data_db; Integrated Security=SSPI";//本地连接
conn = new SqlConnection(connstr);
conn.Open();
}
else if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
else if (conn.State == ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
return conn;
}
}`
2)字符串保存在app.config文件中定义
app.config文件中添加:
数据库连接类中引用:
public static string connstr = Co