简体   繁体   English

如何与本地数据库连接

[英]How to connect with local database

I downloaded SQL Server Management Studio (SSMS). 我下载了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. 我可以使用Windows身份验证来连接本地数据库,但是我想使用连接字符串来连接我的C#应用​​程序。

I check SQL Server Authentication mode here: 我在这里检查SQL Server身份验证模式:

Photo 照片

I went to Users tab of my new created database. 我转到新创建的数据库的“ Users选项卡。 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上的数据库连接

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/

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

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