web.config里连接数据库问题
config里:
<appSettings>
<add key="Connectionstring" value="Server=(local);database=RBBBS;uid=sa;pwd =">
</add>
程序里:
- C# code
SqlConnection monn=new SqlConnection(Session["str_connection"].ToString());monn.Open();
运行报错:Login failed for user 'sa'
这应该是数据库登陆方式的错误吧,因为我数据库是sql2005,是windows登陆方式
咋办啊?windows登陆方式写在confjg里,怎么写?
[解决办法]
Data Source=(local);Initial Catalog=databasename;Integrated Security=True
[解决办法]
设置混合模式安全性
展开一个服务器组。
右击一个服务器,再单击"属性"。
单击"安全性"选项卡。
在"身份验证"下,单击"SQL Server 和 Windows"。
在"审核级别"中选择在 SQL Server 错误日志中记录的用户访问 Microsoft® SQL Server™ 的级别:
"无"表示不执行审核。
"成功"表示只审核成功的登录尝试。
"失败"表示只审核失败的登录尝试。
"全部"表示审核成功的和失败的登录尝试。
[解决办法]
- C# code
public readonly string ConnStr = ConfigurationManager.AppSettings["connstr"];
[解决办法]
"Persist Security Info=False;Integrated Security=true;Initial Catalog=Northwind;server=(local)"
[解决办法]
为什么连接字符串是写在webconfig.xml中的却写到session中?
而且应该以Connectionstring作为引用名.
[解决办法]
楼主:
[color=#00FF00] <add key= "Connectionstring " value= "Server=(local);database=RBBBS;uid=sa;pwd = "> [/color]
改成
[color=#FF0000] <add key= "Connectionstring " value= "Server=(local);database=RBBBS;uid=sa;pwd =; "> [/color]
[解决办法]
第一步 在服务器名称上 右键选择道具(最下面个)
在出来的界面中选择 安全性(Security)
把SQL Server and windows....选上
第二步 找到sa用户 右键选择道具(最下面)
在出来的界面打开状态(Status) 把login里面的Enabled选上 就可以了
[解决办法]
忘了 最后restart还要一下