且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

新服务器上的Windows身份验证登录失败

更新时间:2022-10-20 16:36:34

您是否尝试在SQL Management Studio中进行连接?并且您已经检查过sql配置了吗?


为了知道什么是连接字符串,请创建一个文本文件并将其扩展名更改为udl,例如:ConnectionString.udl,然后单击它完成设置测试后,您将看到一个对话框,现在在进行设置

连接,然后单击确定

现在,右键单击ConnectionString.udl文件并使用记事本打开它,您将在 ^ ]告诉您使用当前Windows帐户凭据进行身份验证.您必须更改SQL Express的某些安全设置.
而且,将程序作为服务运行或在Visual Studio下运行是不一样的.


Dear programmer,

I have backuped my sql database and restored on another computer. Now when I try to login to it programatically using C# I get error: "Login failed for user ''new computer name''".
I am using windows authentication and my connection string looks like this:
Data Source=.\\sqlexpress;Initial Catalog="office_ session";Integrated Security=True

when I try Visual studio -> server explorer -> connect to a database wizard
everything works fine.

Thank you for your time

did you try to connect it in SQL Management Studio? And did you already check your sql configuration?


In order to know what is the connection string create a text file and change the extension of it to udl eg:ConnectionString.udl and click on it you will see a dialog now do the settings once you have done the settings test the

connection and then click on OK

Now right click the ConnectionString.udl file and open it with notepad you will get the connection string


Integrated Security in the connection string[^] tell to use the current Windows account credentials for authentication. You have to change some security settings for SQL Express.
And running you program as a service or under Visual Studio is not the same.