读者你好:
关于连接数据库,请参考下面的说明:
1:连接SQL Server:
string strConnection="uid=sa; password=; ";
strConnection+="initial catalog=Northwind;Server=YourSQLServer;";
strConnection+="Connect Timeout=30";
SqlConnection objConnection=new SqlConnection(strConnection);
..
objConnection.Open();
objConnection.Close();
"uid=sa":连接数据库的用户名为sa.
"password=":连接数据库的验证密码为空.他的别名为"pwd",所以我们可以写为"pwd=".
"initial catalog=Northwind":使用的数据源为"Northwind"这个数据库.他的别名为"Database",本句可以写成"Database=Northwind".
"Server=YourSQLServer":使用名为"YourSQLServer"的服务器.他的别名为"Data Source","Address","Addr".
" Connect Timeout=30":连接超时时间为30秒.(根据情况添加)
2、连接ACCESS
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection+=@"Data Source=C:\Northwind.mdb";
OleDbConnection objConnection=new OleDbConnection(strConnection);
...
objConnection.Open();
..
objConnection.Close();