Skip to content
Rishan Solutions
Rishan Solutions
  • PowerApps
  • SharePoint online
    • Uncategorized
    • Uncategorized
  • PowerAutomate
Rishan Solutions
Latest Posts
  • Recursive Queries in T-SQL May 7, 2025
  • Generating Test Data with CROSS JOIN May 7, 2025
  • Working with Hierarchical Data May 7, 2025
  • Using TRY_CAST vs CAST May 7, 2025
  • Dynamic SQL Execution with sp_executesql May 7, 2025
  • GROUPING SETS, CUBE, and ROLLUP May 7, 2025

“Database connection string is incorrect” – Configuration error with the database connection string.

Posted on March 7, 2025March 7, 2025 by Zubair Shaik

Loading

Fixing “Database Connection String is Incorrect” – A Detailed Guide

A database connection string is a critical part of any application that connects to a database. If the connection string is incorrect, the application will fail to connect, leading to errors and possible downtime. This guide will provide a detailed step-by-step approach to identify, troubleshoot, and resolve configuration errors related to the database connection string.


Step 1: Identify the Issue

Before making any changes, confirm that the issue is actually due to an incorrect connection string.

Check Error Messages

  • If you are using an application, check the error logs for a message similar to:
    • “Database connection string is incorrect.”
    • “Login failed for user.”
    • “The network path was not found.”
    • “Timeout expired.”
  • If using SQL Server, check error logs in SQL Server Management Studio (SSMS): EXEC xp_readerrorlog 0, 1, 'login failed';

Check Application Logs

  • If using a .NET application, check the Event Viewer (eventvwr.msc) under Windows Logs → Application.
  • If using PHP or Python, check the respective error logs:
    • PHP: /var/log/apache2/error.log (Linux) or C:\xampp\apache\logs\error.log (Windows)
    • Python Django: logs/django.log

Step 2: Verify the Connection String Format

A connection string must be correctly formatted based on the database type. Below are common formats:

SQL Server (MSSQL)

Windows Authentication

Server=YourServerName;Database=YourDatabaseName;Trusted_Connection=True;

SQL Authentication

Server=YourServerName;Database=YourDatabaseName;User Id=YourUsername;Password=YourPassword;

With Instance Name

Server=YourServerName\InstanceName;Database=YourDatabaseName;User Id=YourUsername;Password=YourPassword;

With Port

Server=YourServerName,1433;Database=YourDatabaseName;User Id=YourUsername;Password=YourPassword;

MySQL

Server=YourServerIP;Database=YourDatabaseName;User Id=YourUsername;Password=YourPassword;

PostgreSQL

Host=YourServerIP;Database=YourDatabaseName;Username=YourUsername;Password=YourPassword;

Step 3: Verify Database Server Accessibility

Even if the connection string is correct, the database server might not be reachable.

Ping the Database Server

  1. Open Command Prompt (cmd) and type: ping YourServerName
    • If it responds, the server is accessible.
    • If not, check firewall settings and network configurations.

Check SQL Server TCP/IP Settings

  1. Open SQL Server Configuration Manager.
  2. Go to SQL Server Network Configuration → Protocols for MSSQLSERVER.
  3. Ensure TCP/IP is enabled.
  4. Restart SQL Server service.

Check Database Port

  1. Open Command Prompt and run: netstat -an | find "1433" If 1433 (default SQL port) is not listed, the database might not be listening on the correct port.
  2. To check in SQL Server: SELECT local_net_address, local_tcp_port FROM sys.dm_exec_connections WHERE protocol_desc = 'TCP';

Step 4: Verify Authentication Credentials

Incorrect username or password can also cause connection issues.

Check Login Credentials in SQL Server

  1. Open SSMS.
  2. Run: SELECT name, type_desc FROM sys.server_principals WHERE type_desc = 'SQL_LOGIN';
  3. Ensure the user exists and has the correct permissions: EXEC sp_helplogins 'YourUsername';
  4. If needed, reset the password: ALTER LOGIN YourUsername WITH PASSWORD = 'NewPassword';

Step 5: Test the Connection String Manually

Using SQLCMD

  1. Open Command Prompt and type: sqlcmd -S YourServerName -d YourDatabaseName -U YourUsername -P YourPassword
    • If it connects, the credentials are correct.
    • If it fails, check the error message.

Using a UDL File (Windows)

  1. Create a .txt file and rename it to Test.udl.
  2. Double-click the file and enter the database details.
  3. Click Test Connection.
  4. If it fails, adjust the settings.

Step 6: Ensure Firewall & Network Configurations are Correct

Firewalls may block the database connection.

Check Firewall Rules

  1. Open Windows Defender Firewall (wf.msc).
  2. Go to Inbound Rules → Look for SQL Server (TCP-In).
  3. If not found, add a new rule:
    • Protocol: TCP
    • Port: 1433
    • Allow Connection

Ensure Remote Connections are Enabled

  1. Open SSMS.
  2. Run: EXEC sp_configure 'remote access';
  3. If run_value is 0, enable it: EXEC sp_configure 'remote access', 1; RECONFIGURE;

Step 7: Check Application Configuration Files

Ensure the application is using the correct connection string.

.NET (Web.config / App.config)

<connectionStrings>
    <add name="DefaultConnection" connectionString="Server=YourServerName;Database=YourDatabaseName;User Id=YourUsername;Password=YourPassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>

PHP (config.php)

$servername = "YourServerIP";
$username = "YourUsername";
$password = "YourPassword";
$database = "YourDatabaseName";

$conn = new mysqli($servername, $username, $password, $database);

Python Django (settings.py)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'YourDatabaseName',
        'USER': 'YourUsername',
        'PASSWORD': 'YourPassword',
        'HOST': 'YourServerIP',
        'PORT': '5432',
    }
}

Step 8: Restart Services & Verify

  1. Restart SQL Server Services
    • Open Services.msc → Restart SQL Server (MSSQLSERVER).
    • Restart IIS (for web applications) using: iisreset
  2. Test the Connection Again
    • Run the application and check if the error persists.

Step 9: Set Up Logging for Future Issues

To prevent future connection issues, set up logging.

Enable SQL Server Logging

EXEC xp_readerrorlog;

Enable Application Logging

  • In .NET, enable detailed logging in appsettings.json: { "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "System": "Error" } } }

Posted Under SharePoint onpremiseApplication Database Settings Connection String Troubleshooting Database Configuration Database Connection Debugging Database Connection String Firewall SQL Server MySQL Connection Issues PHP MySQL Connection PostgreSQL Connection Error Python Database Connection SQL Authentication Error SQL Server Connection Error SQL Server Login Failed SQL Server Network Issues SQL Server Remote Access SQL Server TCP/IP SQLCMD Test Connection Test Database Connection Web Config Connection String

Post navigation

Flow not triggered – The flow did not trigger as expected, often due to incorrect trigger configurations
Timeout expired – Flow exceeded the allowed execution time.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Recursive Queries in T-SQL
  • Generating Test Data with CROSS JOIN
  • Working with Hierarchical Data
  • Using TRY_CAST vs CAST
  • Dynamic SQL Execution with sp_executesql

Recent Comments

  1. Michael Francis on Search , Filter and Lookup in power apps
  2. A WordPress Commenter on Hello world!

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • March 2024
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • January 2022

Categories

  • Active Directory
  • AI
  • AngularJS
  • Blockchain
  • Button
  • Buttons
  • Choice Column
  • Cloud
  • Cloud Computing
  • Data Science
  • Distribution List
  • DotNet
  • Dynamics365
  • Excel Desktop
  • Extended Reality (XR) – AR, VR, MR
  • Gallery
  • Icons
  • IoT
  • Java
  • Java Script
  • jQuery
  • Microsoft Teams
  • ML
  • MS Excel
  • MS Office 365
  • MS Word
  • Office 365
  • Outlook
  • PDF File
  • PNP PowerShell
  • Power BI
  • Power Pages
  • Power Platform
  • Power Virtual Agent
  • PowerApps
  • PowerAutomate
  • PowerPoint Desktop
  • PVA
  • Python
  • Quantum Computing
  • Radio button
  • ReactJS
  • Security Groups
  • SharePoint Document library
  • SharePoint online
  • SharePoint onpremise
  • SQL
  • SQL Server
  • Template
  • Uncategorized
  • Variable
  • Visio
  • Visual Studio code
  • Windows
© Rishan Solutions 2025 | Designed by PixaHive.com.
  • Rishan Solutions