简体   繁体   English

如何将SQL Server 2005从Windows身份验证更改为SQL身份验证?

[英]How to change SQL Server 2005 from Windows Authentication to SQL Authentication?

I have installed SQL Server 2005 in Windows Authentication, now I want to change it to SQL Authentication. 我已经在Windows身份验证中安装了SQL Server 2005,现在我想将其更改为SQL身份验证。 However, I cannot reinstall SQL SERVER and Management again, because it will lose the data in it. 但是,我无法再次重新安装SQL SERVER和管理,因为它将丢失其中的数据。 Also I want to know what changes do I need to make in my Connection class to open connection, as my current is 我也想知道我需要在Connection类中进行哪些更改以打开连接,因为当前

public SqlConnection con= new sqlConnection("server=.\\SQLEXPRESS;database=Restaurant;integrated security=sspi");

Just need to ask one more thing, I can see my database in WIndows Auth and in SQL auth, so how can i change, so that any other user need to login before it peeps into my database. 只需要再问一件事,我就可以在WIndows Auth和SQL auth中看到我的数据库,因此我该如何更改,以便任何其他用户需要先登录才能窥探我的数据库。 thanks 谢谢

Using SQL Server Management Studio * To change security authentication mode * 使用SQL Server Management Studio * 更改安全身份验证模式 *

In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties. 在SQL Server Management Studio对象资源管理器中,右键单击服务器,然后单击“属性”。

On the Security page, under Server authentication, select the new server authentication mode, and then click OK. 在“安全性”页上的“服务器身份验证”下,选择新的服务器身份验证模式,然后单击“确定”。

In the SQL Server Management Studio dialog box, click OK to acknowledge the requirement to restart SQL Server. 在“ SQL Server Management Studio”对话框中,单击“确定”以确认重新启动SQL Server的要求。

In Object Explorer, right-click your server, and then click Restart. 在对象资源管理器中,右键单击您的服务器,然后单击“重新启动”。 If SQL Server Agent is running, it must also be restarted. 如果SQL Server代理正在运行,则还必须重新启动它。

To enable the sa login 启用sa登录

In Object Explorer, expand Security, expand Logins, right-click sa, and then click Properties. 在对象资源管理器中,依次展开“安全性”,“登录名”,右键单击“ sa”,然后单击“属性”。

On the General page, you might have to create and confirm a password for the login. 在“常规”页面上,您可能必须创建并确认登录密码。

On the Status page, in the Login section, click Enabled, and then click OK. 在“状态”页面上的“登录”部分,单击“启用”,然后单击“确定”。

Using Transact-SQL To enable the sa login 使用Transact-SQL启用sa登录

In Object Explorer, connect to an instance of Database Engine. 在对象资源管理器中,连接到数据库引擎的实例。

On the Standard bar, click New Query. 在“标准”栏上,单击“新建查询”。

Copy and paste the following example into the query window and click Execute. 将以下示例复制并粘贴到查询窗口中,然后单击“执行”。 The following example enables the sa login and sets a new password. 以下示例启用sa登录并设置新密码。

ALTER LOGIN sa ENABLE ;
GO
ALTER LOGIN sa WITH PASSWORD = '<enterStrongPasswordHere>' ;
GO

You can pass below sample(change appropriate UID & PWD) connection string in your connection object 您可以在连接对象中传递以下示例(更改适当的UID和PWD)连接字符串

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

To use SQL Server authentication, change the line: 要使用SQL Server身份验证,请更改以下行:

public SqlConnection con= new sqlConnection("server=.\\SQLEXPRESS;database=Restaurant;integrated security=sspi");

to

public SqlConnection con= new sqlConnection("server=.\\SQLEXPRESS;database=Restaurant;user id=#USERID#;password=#PASSWORD#;Trusted_Connection=False");

Where "#USERID#" and #PASSWORD# are the specific User ID and Password respectively 其中“#USERID#”和“#PASSWORD#”分别是特定的用户ID和密码

To change the server security type: You just need open SQL Server Management Object Explorer, right click the server, go in Properties, Security page, under server authentication, select the mode you want. 更改服务器安全性类型:您只需要打开SQL Server管理对象资源管理器,右键单击服务器,进入“属性”,“安全性”页面,在服务器身份验证下,选择所需的模式。

To modify the connection string: 1. You need to have a SQL user first. 修改连接字符串:1.首先需要有一个SQL用户。 Still in the SQL Server Management Object Explorer, right click on user which under Security node, click new, then you can create one. 仍在SQL Server管理对象资源管理器中,右键单击“安全”节点下的用户,单击“新建”,然后可以创建一个。 2. add the "User ID" and "Password" segment to the connection string. 2.将“用户ID”和“密码”段添加到连接字符串。

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

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