Only able to connect to a SQLServer Database using Integrated Security

0

I am trying to connect to a database with a Process account, but I am only able to connect using IntegratedSecurity. If I try to set it manually the application throws an error due to not being able to login with the user.

I tried to run this code on different languages, but same issue happens.

class Program {
    static void Main(string[] args) {
        try {
            Console.WriteLine("Connect to SQL Server and demo Create, Read, Update and Delete operations.");
            // Build connection string
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
            builder.DataSource = "datasource";
            builder.InitialCatalog = "warehouse";
            builder.UserID = "user";
            builder.Password = "pass#$word";
            //builder.IntegratedSecurity = true;
            // Connect to SQL
            Console.WriteLine("Connecting to SQL Server ... ");
            Console.WriteLine(builder);
            using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) {
                connection.Open();
                Console.WriteLine("Done.");
            }
        }
        catch (SqlException e) {
            Console.WriteLine(e.ToString());
        }
        Console.WriteLine("All done. Press any key to finish...");
        Console.ReadKey(true);
    }
}

I expect to be able to connect to the database without the need of the IntegratedSecurity.

Also, this is to a remote server, not local host. I am able to connect in SSMS using Windows Authentication, but if I try to set it to pass the credentials hard-coded, it throws an error message.

The error (from the comments)

Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user 'user'. at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)

c#
sql
sql-server
asked on Stack Overflow Jun 25, 2019 by christopher schneider • edited Jun 25, 2019 by christopher schneider

1 Answer

-1

Just make

builder.IntegratedSecurity = false;

It will work.

answered on Stack Overflow Jun 25, 2019 by Pankaj Moriya

User contributions licensed under CC BY-SA 3.0