以SQL Server 验证模式连接代码如下
string strConection="user id=此处你登录数据库的用户名;password=登录密码";
strConection+="initial catalog=数据库名字;Server=数据库服务器名字";
strConnection+="Connect Timeout=30";
示例
string strConection="user id=zhidao91;password=1234456";
strConection+="initial catalog=zhidao91database;Server=.\sqlexpress";
strConnection+="Connect Timeout=30";
如果在Web.config中设置连接字符串,参考如下:
本地连接(数据库在本机)
远程连接(数据库不在本机)
若C#程序连接数据库时报如下或类似错误:
[Win32Exception (0x80004005): The system cannot find the file specified]
[SqlException (0x80131904): A network-related or instance-specific error
occurred while establishing a connection to SQL Server. The server was
not found or was not accessible. Verify that the