How to fix error ::Format of the initialization string does not conform to specification starting at index 0::
Asked Answered
L

20

21

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);...

Lawful answered 27/1, 2012 at 21:22 Comment(6)
Do you have the stack trace for the exception?Bobsleigh
Yes I have but there is nothing important. This must be something with connection string. I tried to rename it to 'LocalSqlServer' but nothing.Lawful
How is your code referencing the connection string?Bobsleigh
I am using 'ninject IOC'. In global.asax I have 'Bind<ICountriesRepository>().To<CountriesRepository>().WithConstructorArgument( "connectionString", ConfigurationManager.ConnectionStrings["mcn"].ConnectionString);' Code is fine. As I said it works on my PC. It doesn't work on live server.Lawful
Do you get the same error if you copy the entire Web.config file—exactly as is—back from GoDaddy to your own PC?Bobsleigh
When I do that I get the same error. Here how I build application. I build it normally and right click on project and select Build Deployment Package. Then I copy all from .../obj/debug/package/packageTmp to server. In web config instead whole connection string I have: <add name="mcn" connectionString="$(ReplacableToken_mcn-Web.config Connection String_0)" providerName="System.Data.SqlClient" />Lawful
B
20

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.

Bobsleigh answered 27/1, 2012 at 23:38 Comment(3)
Now I have checked and yes my connection string is '$(ReplacableToken_mcn-Web.config Connection String_0)' So I have copied my normal web/config to host server and it works. But is it ok? Have I make some security issue now?Lawful
I wouldn't worry that there is a security issue; Web.config is protected from browsing by Internet users. Just make sure your database password is unique to GoDaddy, because GoDaddy administrators can see your password.Bobsleigh
@MichaelLiu +1 just been had by this.Chaudfroid
B
5

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.

Blaney answered 18/9, 2012 at 23:47 Comment(1)
IMHO, this answers a more general version of the question in a way that may help more users arriving here wondering WTF "Format of the initialization string does not conform to specification starting at index 0." means.Va
E
4

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.

Expecting answered 24/8, 2017 at 20:41 Comment(1)
This was actually a problem for me too when using the EF Core CLI tools. The connection string worked everywhere else except when using those tools. Removing the quotes solved the issue immediately.Ownership
L
3

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
Lunt answered 3/7, 2013 at 15:12 Comment(0)
P
2

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.

Principe answered 25/9, 2015 at 9:5 Comment(0)
P
2

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.

Peril answered 14/5, 2017 at 15:16 Comment(1)
I see nothing special in my password but this definitely worked. Thank you!Cheryl
M
1

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.

Malmo answered 30/12, 2013 at 12:13 Comment(0)
S
0

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.

Storiette answered 13/12, 2012 at 1:47 Comment(0)
L
0

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.

Latrell answered 17/2, 2014 at 18:40 Comment(0)
V
0

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)
    {
    }
}
Veda answered 10/12, 2014 at 1:11 Comment(0)
E
0

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.

Event answered 11/6, 2016 at 16:42 Comment(0)
T
0

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

Turtledove answered 18/7, 2016 at 10:29 Comment(0)
S
0

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.

Sciomachy answered 20/7, 2016 at 20:40 Comment(0)
S
0

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.

Sitka answered 25/7, 2017 at 1:55 Comment(0)
V
0

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

Va answered 3/10, 2017 at 12:33 Comment(0)
I
0

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.

Israel answered 1/3, 2019 at 14:14 Comment(0)
S
0

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.

Sloatman answered 12/8, 2019 at 14:14 Comment(0)
C
0

This helped me in the config. Although I did not change my framework Visual Studio 2022 seemed to insist upon it and once all those other changes.

in the startup section

supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"

I did not check other versions as I am under a deadline crunch on other stuff

Carline answered 22/3, 2023 at 15:48 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewAdao
R
0

solved above error by add Configuration instead of just string path change

services.AddDbContext<ProductDbContext>(opts => {
                opts.UseSqlServer("ConnectionStrings:AppDataConnection");
            });

to

services.AddDbContext<ProductDbContext>(opts => {
                opts.UseSqlServer(Configuration["ConnectionStrings:AppDataConnection"]);
            });
Rrhoea answered 6/6, 2023 at 14:6 Comment(0)
A
-1

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

here we have the same situation.

Adelladella answered 30/6, 2020 at 18:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.