将用户和密码添加到Sql Server数据库

Ann*_*a T 5 sql-server-2005

我在Web.Config中定义的连接字符串当前表示不需要用户或密码:

<connectionStrings>
    <add name="CinemaxConnectionString" connectionString="Data Source=PCName\SQLEXPRESS;Initial Catalog=Cinemax;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

我想添加用户名和密码,如下所示:

<connectionStrings>
    <add name="CinemaxConnectionString" connectionString="Data Source=PCName\SQLEXPRESS;Initial Catalog=Cinemax;User=cinemax; Password=abc"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
Run Code Online (Sandbox Code Playgroud)

显然,这需要更改Sql Server中的某些设置以添加用户和密码.做这个的最好方式是什么?我指定我有Sql Server 2005 Express,当前的身份验证模式是"Sql Server和Windows身份验证".预先感谢您的帮助.很高兴看到对此的双重看法:用户界面和代码解决方案.

Raj*_*esh 13

以下陈述将为您完成工作.

CREATE LOGIN cinemax WITH PASSWORD = 'abc';

GO

CREATE USER cinemaxUser FOR LOGIN cinemax

GO

GRANT SELECT TO cinemaxUser

GO

GRANT INSERT TO cinemaxUser

GO

GRANT UPDATE TO cinemaxUser

GO

GRANT DELETE TO cinemaxUser

GO
Run Code Online (Sandbox Code Playgroud)