Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding user and password to Sql Server database

My connection string defined in Web.Config currently indicatea no user or password is needed:

<connectionStrings>
    <add name="CinemaxConnectionString" connectionString="Data Source=PCName\SQLEXPRESS;Initial Catalog=Cinemax;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

I would like to add user and password, like this:

<connectionStrings>
    <add name="CinemaxConnectionString" connectionString="Data Source=PCName\SQLEXPRESS;Initial Catalog=Cinemax;User=cinemax; Password=abc"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

Obviously, this requires changing some settings in Sql Server to add user and password. What is the best way to do this? I specify I have Sql Server 2005 Express and the current authentcation mode is "Sql Server and Windows Authentication". Thank you in advance for your help. It would be nice to see a double take on this: user-interface and code solution.

like image 427
Anna T Avatar asked Jun 08 '12 09:06

Anna T


People also ask

How do I create a username and password for a database?

Right-click the Security folder, point to New, and select User.... In the Database User - New dialog box, on the General page, select one of the following user types from the User type list: SQL user with login. SQL user with password.

What is the difference between SQL Server login and user?

A login provides to a user or application the ability to connect to a SQL Server instance, whereas a database user provides the login rights to access a database. Each database a login needs access to will require a database user to be defined, except when a login has been given sysadmin rights.


1 Answers

The below statements would do the job for you.

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
like image 108
Rajesh Avatar answered Sep 18 '22 22:09

Rajesh