[asp.net] How to fix error ::Format of the initialization string does not conform to specification starting at index 0::

I uploaded my site on godaddy shared host. I can access this database from my management studio. I can't access this database from my site. I get following error:

Format of the initialization string does not conform to specification starting at index 0.

My connection string is in web.config and it looks like this:

<connectionStrings>
    <add name="mcn" connectionString="Data Source=mydatabase.db.8706856.hostedresource.com; Initial Catalog=mydatabase; User ID=username; Password=xyz;" providerName="System.Data.SqlClient" />    
</connectionStrings>

What cause this error? I have also tried to write ...Data Source=(local);...

This question is related to asp.net connection-string

The answer is


It might help to see what the actual connection string is. Add to Global.asax:

throw new Exception(ConfigurationManager.ConnectionStrings["mcn"].ConnectionString);

If the actual connection string is $(ReplacableToken_mcn-Web.config Connection String_0), that would explain the problem.


My issue was that my web.config file kept a reference to a deleted entity model connection so check there are not any outdated connection strings.


In my Case, it is because of having more than one connection string in your Solution. one for your current project and the other one for a startup project in your Solution. for more information please refer to Telerik report not working

here we have the same situation.


If you're using EF and Publish Profiles, you could have a blank connection string entry in your publish profile. Annoying but entirely possible.


I got below error when trying to launch application :

Format of the initialization string does not conform to specification starting at index 57.

And during my research I found this stack and I was able to fix this error by looking at the web config file and found there was a extra string in the passowrd. Once I removed the string I was able to access the website without any error.


Another pitfall is that connectionString sometimes refers to the name of the connection string in the app/web-config and sometimes to the actual connection string itself and vice versa.

Very easy to fix but sometimes hard to spot.


I was facing the same problem and found out that my connection string had an extra double-quote character in the middle of the connection string.


For my case, the culprit was the semicolon and double quotes in the password for prod DB. Our IT team use some tool to generate passwords, so it generated one with the semicolon and double quotes Connectionstring looks like

<add key="BusDatabaseConnectionString" value="Data Source=myserver;Initial Catalog=testdb;User Id=Listener;Password=BlaBla"';[]qrk/>

Got the password changed and it worked.


I was having the same issue when accessing a published ASP.NET Web Api. In my case, I realized that when I was about to publish the Web Api, I had not indicated a connection string inside the Databases section:

After using the three dot button, the connection string will be displayed on the text field to the left

So I generated it using the three dot button, and after publishing, it worked.

What is weird, is that for a long time I am pretty sure that there was no connection string in that configuration but it still worked.


I originally was calling the connection string value as shown below (VB.NET) and got the error being mentioned

 Using connection As New SqlConnection("connectionStringName") 
  '// more code would go here...
 End Using

adding a reference to System.Configuration and updating my code as shown below was my solution. The connection string was not the problem since others controls used it without any issues (SqlDataSource)

Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("connectionStringName").ConnectionString)
    '// more code would go here...
End Using

I was getting this exception, fixed it by adding throwIfV1Schema: false to my DbContext constructor:

public class AppDb : IdentityDbContext<User>
{
    public AppDb()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
    }
}

I had the same error message in my localhost development with my Visual Studio. Note that everything was working when released with Microsoft Release Management (MRM). I fixed my situation by changing the initial value that was a MRM reference.

My App.config initial value was the following:

  <connectionStrings>
    <add name="BDORA" connectionString="__token3__" />
  </connectionStrings>

Locally, the application execution could not interpret the token3 reference to its real value in Tokens.xml. To make it work on my localhost, I had to force the value from token3 in Tokens.xml into the App.config file.


I had this in VS2015 and my fix was to change the first line in my WebConfig from

<?xml version="1.0" encoding="utf-8"?>

to

<?xml version="1.0"?>

Curious.


My fix was suprisingly simple and another one of those obvious when you realise what you've done. I was manually building the configuration using .NET Core/Standard in the following fashion:

var configurationBuilder = new ConfigurationBuilder();
var root = configurationBuilder.Build(); 

and had forgotten to include the appsettings.json file that had my configuration settings in it

configurationBuilder.AddJsonFile("appsettings.json", false);

Once added, all started working once more.


An unwanted single quote was my problem. Checking the connection string from the location of the index mentioned in the error string helped me spot the issue.


None of the listed solutions in this thread worked for me. I started getting this error after I made some changes to the connection strings section of the web.config file. (My app connects to multiple databases.) I carefully examined what changes I had made are realized I had removed the tag at the top of my list. I restored the tag at the top of my list of connection strings and the problem went away immediately. This site that was getting the error is a application that resides below the main site (https://www.domain.org/MySite). This might not fix the problem for everyone, but it did resolve the problem for me.


I have wasted 1.5 working days on this error and in the end a coworker solved the issue by replacing User Id by Uid and password by Pwd. The updated connection string for .Net was the error for me


For anyone who may stumble across this thread while trying to fix this same error that results by running Enable-Migrations, chances are none of the solutions above will help you (I tried them all).

I encountered this same issue in Web API 2 after running this in PM console:

Enable-Migrations -EnableAutomaticMigrations -ConnectionString IdentityConnection -ConnectionProviderName System.Data.SqlClient -Force

I fixed it by changing it to actually use the ApplicationDbContext created in IdentityModels.

Enable-Migrations -ContextTypeName ApplicationDbContext -EnableAutomaticMigrations -Force

The interesting thing is not only does this reference the same exact connection string, but the constructor includes code that 4castle said was a potential fix (i.e., the throwIfV1Schema: false suggestion.

Note that the -Force parameter is only being used because the Configuration.cs file already exists.


Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to connection-string

Get ConnectionString from appsettings.json instead of being hardcoded in .NET Core 2.0 App How to read connection string in .NET Core? Connect to SQL Server Database from PowerShell System.Data.SqlClient.SqlException: Login failed for user Entity Framework change connection at runtime A network-related or instance-specific error occurred while establishing a connection to SQL Server How can I set an SQL Server connection string? VB.NET Connection string (Web.Config, App.Config) Connection string using Windows Authentication How to find SQL Server running port?