Grant releveant access to a user in SQL Server

Krish 81 Reputation points
2020-09-08T13:11:04.207+00:00

Hi Everyone,
I am new to this area and i request you to suggest me to come out of my confusions.

I have a data base in sql server 2017 as db_test and a user user1. I need to grant permissions to this user. I tried below scripts and executed the scripts with no errors. But when i am trying to log in with this user , i am not able to connect to the server itself. What i am missing here ?

CREATE LOGIN user1 WITH PASSWORD = 'Pa$$word123'
CREATE USER user1
EXEC sp_addrolemember 'db_datareader', 'user1'
GRANT CREATE SCHEMA TO user1
GRANT CREATE PROCEDURE TO user1
GRANT CREATE FUNCTION TO user1

Thanks in advance,

SQL Server Other
{count} votes

4 answers

Sort by: Most helpful
  1. Shashank Singh 6,251 Reputation points
    2020-09-08T13:46:47.353+00:00

    I think Olaf is correct your SQL Server is having currently Windows Authentication Mode you need to enable mixed more authentication. Post that a SQL Server service restart is required to make the change effective

    0 comments No comments

  2. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2020-09-09T03:37:58.16+00:00

    Hi @kirankumar-3620,

    > Cannot open user default database. Login failed. Login failed for user 'user1'. (Microsoft SQL Server, Error: 4064)

    According to the error message, please try to change the user's default database to a database that's currently available for a connection. Please refer to below blogs to get more information.

    Error message when you connect to an instance of SQL Server: "Cannot open user default database"
    SQL SERVER – Fix : Error: 4064 – Cannot open user default database. Login failed. Login failed for user

    If It is not work, please let me know.

    Best regards,
    Cathy


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Olaf Helper 47,436 Reputation points
    2020-09-09T06:31:23.427+00:00
    0 comments No comments

  4. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2020-09-09T07:49:57.803+00:00

    Hi @kirankumar-3620,

    > The database xxx is not accessible. (ObjectExplorer)

    You can also resolve this issue from SSMS UI as below screenshot. Right click user1 login > Properties > User Mapping

    23423-annotation-2020-09-09-154805.jpg

    Best regards,
    Cathy


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.