Hello Everyone,

I have developed an application for website using ASP.NET and SQL Server 2005. Recently I have uploaded it to server, but after uploading its showing the following error message -

Login failed for user ''. The user is not associated with a trusted SQL Server connection.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user ''. The user is not associated with a trusted SQL Server connection.

I wrote following connection string in web.config file-
<appSettings>

<add key="ConnectionString" value="Data Source=;User ID=user;password=pass;Initial Catalog=dbname;Integrated Security=True" />

</appSettings>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="brightlightConnectionString" connectionString="Data Source=;User ID=user;password=pass;Initial Catalog=dbname;Integrated Security=True" providerName="System.Data.SqlClient"/>

</connectionStrings>

Is there anything wrong with the connection string?

Please help me out

Dani AI

Generated

Short diagnosis: the message "Login failed for user ''" usually means the app tried Windows authentication (Integrated Security/SSPI) but SQL Server rejected that account. That commonly happens when a connection string mixes SQL credentials with Integrated Security, or when the web app is running outside the domain the SQL Server trusts. was correct to point at the authentication mode, and later note about forcing a TCP/port connection aligns with common hosting fixes.

Quick checklist and concrete steps to resolve:

  • Ensure SQL Server is set to mixed mode (SQL Server and Windows Authentication) and restart the SQL service if you change it.

  • Create a dedicated SQL login and map it to the database with only the permissions the app needs. Example T‑SQL to create a login and database user:

    CREATE LOGIN app_login WITH PASSWORD = 'StrongP@ssw0rd!';
    USE YourDatabase;
    CREATE USER app_login FOR LOGIN app_login;
    EXEC sp_addrolemember 'db_datareader', 'app_login';
    EXEC sp_addrolemember 'db_datawriter', 'app_login';
  • Use a connection string that matches the chosen auth mode (do not leave Integrated Security=True when supplying SQL username/password). A safe template:

    <connectionStrings>
      <add name="MyConn"
           connectionString="Server=tcp:your.sql.host,1433;Database=YourDb;User Id=app_login;Password=StrongP@ssw0rd!"
           providerName="System.Data.SqlClient" />
    </connectionStrings>
  • Enable TCP/IP in SQL Server Configuration Manager, start SQL Server Browser for named instances (or specify the instance port), and open the server firewall for the SQL port (default 1433).

How to verify: from the web host (or an equivalent machine) test connectivity with sqlcmd or telnet, e.g.:

sqlcmd -S tcp:your.sql.host,1433 -U app_login -P 'StrongP@ssw0rd!'

Additional notes: check the SQL Server error log for the precise failure state, avoid embedding high‑privilege credentials in clear text (use Protected Configuration / config encryption), and prefer a least‑privilege SQL account for the web app.

Recommended Answers

All 4 Replies

Hello Catherine,

When I run the application in my local computer it was ok. I am getting the error after uploading it to the server.

Which authentication mode do you use?If you are using Windows Authentication, please change it to mixed mode and try again.

Which authentication mode do you use?If you are using Windows Authentication, please change it to mixed mode and try again.

Thanx a lot for your reply. I had solved it with following connectionstring setting-

<appSettings>

<add key="ConnectionString" value="Data Source=,1433;Network Library=DBMSSOCN;Initial Catalog=regleinfotech;User ID=regleinfotech;Password=regleinfotech;" />

</appSettings>
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="regleinfotechConnectionString" ConnectionString="Data Source=,1433;Network Library=DBMSSOCN;Initial Catalog=regleinfotech;User ID=regleinfotech;Password=regleinfotech;Integrated Security=True" providerName="System.Data.SqlClient"/>

</connectionStrings>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.