Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

New Post: DBContext Connection problems with SQL2012 contained database users?

$
0
0

Hi there,

in my Situation "UserOne" is a contained database user (without sqllogin) and the user is dbo in the contained database.
With this user i create other "user with password" in the contained database.
The CREATE USER WITH PASSWORD Statement executed with the Entity Framework works and the new user is in the database.

But after that, the next SQL-Access (e.g. SELECT * FROM Products) of "UserOne" through the Entity Framework crashes with the Error.
2012-11-22 11:29:10.17 Logon Login failed for user 'S-1-9-3-3794712727-1332191744-3365646766-2628027274.'. Reason: Could not find a login matching the name provided. [CLIENT: 127.0.0.1]
2012-11-22 11:29:10.17 spid55 Error: 18056, Severity: 20, State: 5.
2012-11-22 11:29:10.17 spid55 The client was unable to reuse a session with SPID 55, which had been reset for connection pooling. The failure ID is 5. This error may have been caused by an earlier operation failing. Check the error logs for failed operations immediately before this error message.

There is no problem with any SQL statement my entity framework fires until I come to the point of creating a new application user which is a new "user with password" in our contained database. The stored procedure executes without any error but the next SQL statement crashes.

This is my stored procedure:
USE[ixxais]
GO
/****** Object:  StoredProcedure [dbo].[AddUser]    Script Date: 22.11.2012 13:02:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTERPROCEDURE[dbo].[AddUser]
@benutzer AS SYSNAME,
@passwort AS SYSNAME
AS
BEGIN

DECLARE@myError int

EXEC('CREATE USER ['+@benutzer +'] WITH PASSWORD = '''+@passwort +''', DEFAULT_SCHEMA= [dbo], DEFAULT_LANGUAGE=[NONE];
       GRANT CONNECT TO ['
+@benutzer +'];
    ALTER ROLE [db_owner] ADD MEMBER ['
+@benutzer +'];
    GRANT ALTER ANY USER TO ['
+@benutzer +']')

SELECT@myError =@@Error

RETURN@myError

END


Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>