[英]Why LinqPad can connect the Db while my console app. throws an SQL Exception for the same code?
I run the code below 我运行下面的代码
var connectionString="Data Source=MyFooServer.myDomaion.com;Initial Catalog=FooDb;Integrated Security=True; MultipleActiveResultSets=true";
using (var con = new SqlConnection(connectionString))
{
var q = "SELECT COUNT(*) FROM Pizza";
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = q;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
reader = cmd.ExecuteReader();
con.Close();
}
from 2 different places: 来自2个不同的地方:
1) LinqPad 1)LinqPad
2) A Console application in Visual Studio 2010 2)Visual Studio 2010中的控制台应用程序
LinqPad works fine. LinqPad工作正常。 No exceptions.
没有例外。 But the same code throws an SQL exception : "The target principal name is incorrect. Cannot generate SSPI context."
但是同一代码会引发SQL异常 : “目标主体名称不正确。无法生成SSPI上下文。”
QUESTION: Why I can connect to my database without any problem from LinqPad but not from the console application even tough I run the same code? 问题:为什么即使我运行相同的代码也很难从LinqPad连接到数据库,但从控制台应用程序却没有问题,为什么?
重新启动我的机器有帮助...不知道造成此行为困难的根本原因是什么。
尝试使用SQL用户名和密码代替Windows Inegrated Security。
var connctionString="Data Source=MyFooServer.myDomain.com;Initial Catalog=FooDb;Uid=Username; pwd=password"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.