System.Data.sqlclient.SqlException:"Login failed for user 'sa'.The uer is not associated with a tru

一段C#程序usingSystem;usingSystem.Collections.Generic;usingSystem.Data.SqlClient;usingSys... 一段C#程序

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace eg_9._1
{
class Program
{
static void Main(string[] args)
{
string connectionString = @"server=localhost;database=Northwind;uid=sa;pwd=sa";//连接SQL数据库的字符串
SqlConnection mySqlConnection = new SqlConnection(connectionString);//创建SqlConnectiion对象并连接到SQL自带Northwind数据库
//创建SqlCommand对象
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
string commandString = "Slect CustomerID,CompanyName,ContactName,Address" + "From Customer Where CustomerID = 'ALKFI'";
mySqlCommand.CommandText = commandString;
//用connection对象的open()方法打开数据库。
mySqlConnection.Open();
//创建sqldatareader对象,并执行ExecuteReader方法。
SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();
//读取每行记录
mySqlDataReader.Read();
//显示列属性值
Console.WriteLine("mySqlDataReader[\"CustomerID\"] = " + mySqlDataReader["CustomerID"]);
Console.WriteLine("mySqlDataReader[\"CompanyName\"] = " + mySqlDataReader["CompanyName"]);
Console.WriteLine("mySqlDataReader[\"ContactName\"] = " + mySqlDataReader["ContactName"]);
Console.WriteLine("mySqlDataReader[\"Address\"] = " + mySqlDataReader["Address"]);
mySqlDataReader.Close();//关闭数据库
mySqlConnection.Close();//关闭数据库连接
}
}
}
运行的时候出现System.Data.sqlclient.SqlException:"Login failed for user 'sa'.The uer is not associated with a trusted SQL Server connection.这样的错误,求高人指点
展开
 我来答
Sora_no_kiseki
2011-04-26 · TA获得超过911个赞
知道小有建树答主
回答量:993
采纳率:0%
帮助的人:869万
展开全部
SQL Server服务器没有启用混合认证,将认证方式从集成认证改为混合认证
追问
请问怎么改?
求全套代码。
追答
修改注册表  
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\LoginMode
LoginMode的键值:1改成2,2 表示混合模式。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式