在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访
using System;using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
namespace background
{
public class logins
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TZroomConnectionString"].ConnectionString);
/// <summary>
/// 管理员登陆验证
/// </summary>
/// <param name="name">管理员名字</param>
/// <param name="pass">管理员密码</param>
/// <returns></returns>
public bool admin(String name, String pass) {
String T_name = name;
String T_pass = pass;
String sql = "select * from administrator where administrator='" + T_name + "' and password='" + T_pass + "'";
SqlCommand cmd = new SqlCommand(sql,conn);
try
{
conn.Open();
SqlDataReader MyReader = cmd.ExecuteReader();
if (MyReader.Read())
{
return true;
}
else {
return false;
}
}
catch (Exception ex)
{
throw (ex);
}
finally {
conn.Close();
}
}
}
}
我可以进入登陆界面,但是就不可以再进去了。。。就出现上面的问题了。。。
求指点 --------------------编程问答-------------------- 应该是数据库连接的问题。
打印出
ConfigurationManager.ConnectionStrings["TZroomConnectionString"].ConnectionString
看是什么 --------------------编程问答-------------------- 看看ConfigurationManager.ConnectionStrings["TZroomConnectionString"].ConnectionString的内容,看看服务器地址,数据库实例名是否正确,网络是否可以访问 --------------------编程问答-------------------- ConfigurationManager.ConnectionStrings["TZroomConnectionString"].ConnectionString这句在配置文件中是否正确?,
<add name="TZroomConnectionString"
connectionString=" Data Source=localhost; Initial Catalog=jagtest;Persist Security Info=True; User ID=sa;Password=123 " providerName="System.Data.SqlClient" /> --------------------编程问答-------------------- 好的。。谢谢啦。。原来是配置里出了点错。。谢谢各位大侠吖。。下次还会来请教的吖
补充:.NET技术 , C#