简体   繁体   English

C# 中的 SQL Server Express 连接字符串错误

[英]SQL Server Express Connection String Error in C#

I want to run a small C# program.我想运行一个小的 C# 程序。 Its database is on my local host in SQL Server.它的数据库在我的 SQL Server 本地主机上。 Now I want to change it to an SQL Server Express one.现在我想把它改成 SQL Server Express 的。 I have made a database which its name is exactly same with the one in local host, I have made the tables too.我做了一个数据库,它的名字和本地主机上的完全一样,我也做了表。 Now I want to change the connection string.现在我想更改连接字符串。 What syntax should I use?我应该使用什么语法?

I have used this one:我用过这个:

Server = localhost\SQLEXPRESS; Database = MyStore_DB; Trusted_Connection = true

I have used it in MyStore.App.exe.config and MyStore.DataLayer.dll.config files instead of the previous connection string in part ConnectionStrings .我在MyStore.App.exe.configMyStore.DataLayer.dll.config文件中使用了它,而不是ConnectionStrings部分中的先前连接字符串。

But an error occurs.但是发生错误。 Could you please help me if I'm mistaken in any step?如果我在任何步骤中弄错了,你能帮我吗?

error: the picture of the error occured error:发生错误的图片

Your connection string it's wrong.你的连接字符串是错误的。 Once you've declared TrustedConnection=true (you miss the ';' at the end) it means that you will login into the database using Windows Authentication.一旦您声明了TrustedConnection=true (您错过了末尾的“;”),这意味着您将使用 Windows 身份验证登录到数据库。

Beyonds that, if you wanted to login with an specific user and password, you may try this:除此之外,如果您想使用特定的用户名和密码登录,您可以试试这个:

Server=.\\SQLEXPRESS;Database=YourDB;MultipleActiveResultSets=true;User Id=yourUser;Password=yourPassword; Server=.\\SQLEXPRESS;Database=YourDB;MultipleActiveResultSets=true;User Id=yourUser;Password=yourPassword;

Notice I'm using "."注意我用的是“.” instead of localhost而不是本地主机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM