1

There are and remote sql server and local C# app.

I can connect to DB via ssms The command '"C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe" -S server -U user -P password ' performs great

But in code

my ConnectionString:

connectionString="Data Source=Server;Initial Catalog=DB;integrated security=false;User ID=user; Password=password;" providerName="System.Data.SqlClient"

when I try to open connction

        using (var conn = new SqlConnection(_connectionString))
        {
            conn.Open();

I get an error "Cannot open database "DB" requested by the login. The login failed. Login failed for user 'user'"

How can it possible? I have managed to connect by using the same user&pass to this server via ssms!! What other permission should have sql-user to connect to DB via C#-application?

P.S The point is (99.9%) on DB server side. And some permissions on it. Because with another remote Server everything works ok.

1 Answers1

0

By default SSMS connects to the database Master, but your App try to connect to the specific Database. Perhaps you haven't sufficient rights for connection to specified Database. Try to connect to server using SSMS with following command:

"C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe" -S server -d DB -U user -P password

Where the DB is your database name from connection string.

Serge Nazarenko
  • 139
  • 1
  • 6