如何连接本地数据库

时间:2022-06-20 01:44:46

I downloaded SQL Server Management Studio (SSMS). I can connect with local database using Windows Authentication, but I would like to connect with my C# app using connection string.

我下载了SQL Server Management Studio(SSMS)。我可以使用Windows身份验证连接本地数据库,但我想使用连接字符串连接我的C#应用​​程序。

I check SQL Server Authentication mode here:

我在这里检查SQL Server身份验证模式:

Photo

照片

I went to Users tab of my new created database. But I can't add new user. It says that I don't have permission.

我转到我新创建的数据库的“用户”选项卡。但我无法添加新用户。它说我没有得到许可。

I also went to sys user properties, but I can't change password anywhere:

我也去了sys用户属性,但我无法在任何地方更改密码:

Photo

照片

So what should I do? I want to connect with database on VPS with my c# app.s

所以我该怎么做?我想用我的c#app.s连接VPS上的数据库

1 个解决方案

#1


4  

If you want to use the current user that is logged in (Windows Authentication) then you setup the connection string as follows:

如果要使用登录的当前用户(Windows身份验证),则按如下方式设置连接字符串:

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

If you mean that you want to use a SQL Authenticated account, you need to add the SQL login and user, map it to the database you want, and then you can use the following syntax:

如果您要使用SQL Authenticated帐户,则需要添加SQL登录名和用户,将其映射到所需的数据库,然后您可以使用以下语法:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

You can search for more documentation on setting up your App.Config file to have connection strings, and any tweaks to the connection string itself can be found at:

您可以搜索有关设置App.Config文件以获取连接字符串的更多文档,并且可以在以下位置找到对连接字符串本身的任何调整:

https://connectionstrings.com/sql-server/

https://connectionstrings.com/sql-server/

#1


4  

If you want to use the current user that is logged in (Windows Authentication) then you setup the connection string as follows:

如果要使用登录的当前用户(Windows身份验证),则按如下方式设置连接字符串:

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

If you mean that you want to use a SQL Authenticated account, you need to add the SQL login and user, map it to the database you want, and then you can use the following syntax:

如果您要使用SQL Authenticated帐户,则需要添加SQL登录名和用户,将其映射到所需的数据库,然后您可以使用以下语法:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

You can search for more documentation on setting up your App.Config file to have connection strings, and any tweaks to the connection string itself can be found at:

您可以搜索有关设置App.Config文件以获取连接字符串的更多文档,并且可以在以下位置找到对连接字符串本身的任何调整:

https://connectionstrings.com/sql-server/

https://connectionstrings.com/sql-server/