Why sqlConnection.Close () does not close the login?

We have unit tests to verify that our database installation and removal functions work successfully. Unit tests use the SqlClient.SqlConnection class to check the contents of a database before, during, and after.

Our problem is that after using SqlClient.SqlConnection, the deleted drop login part is deleted due to the fact that it claims that the user is currently logged in. Although we called SqlConnection.Close () the login seems to be still open.

Our code looks something like this:

InstallTables();  // function uses smo to create tables in a database.
string connString = CreateLogin("userName", "password");  // create login with smo

// Test the returned connection string connects to the database
using (SqlConnection con = new SqlConnection(connString))
{
    con.Open();
    //test code to read the DB version out of a table
    //Dispose calls con.Close() - I have also tried calling it explicitly
}

DropTables();  // uses smo to drop tables from the database
DropLogin("userName", "password");   // uses smo to drop the login

DropLogin : System.Data.SqlClient.SqlException: login_class_unittest_129418264074692569, .

SqlConnection , DropLogin, .

- , , SqlConnection.Close()?

- ?

+3
2

, , , ( , ):

SQL Server (ADO.NET)

( Pooling=false; ) , .

+8

Source: https://habr.com/ru/post/1791263/


All Articles