The format of the initialization string does not match the specification starting at index 0

I have an ASP.Net application that works fine on my local development machine.

When I run this application online, it shows the following error

The format of the initialization string does not meet the specification starting at index 0

+113
c # sql-server-2008
Nov 23 '11 at 1:30 p.m.
source share
18 answers

Check the connection string. If you need help, check the Connection Strings for a list of the most frequently used ones.

Commonly used connection strings:

SQL Server 2012

Standard security

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword; 

Reliable connection

 Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; 

Connect to an instance of SQL Server

The server / instance name syntax used in the server parameter is the same for all SQL Server connection strings.

 Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername; Password=myPassword; 

SQL Server 2005

Standard security

 Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword; 

Reliable connection

 Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; 

Connect to an instance of SQL Server

The server / instance name syntax used in the server parameter is the same for all SQL Server connection strings.

 Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;Password=myPassword; 

MySQL

Standard

 Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; 

Specify TCP Port

 Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;Pwd=myPassword; 

Oracle

Using TNS

 Data Source=TORCL;User Id=myUsername;Password=myPassword; 

Using Integrated Security

 Data Source=TORCL;Integrated Security=SSPI; 

Using ODP.NET without tnsnames.ora

 Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword; 
+157
Nov 23 2018-11-11T00:
source share

It might help someone. My password contained a semicolon, so she ran into this problem. Also added the password in quotation marks. It was a stupid mistake.

I changed the following:

 <add name="db" connectionString="server=local;database=dbanme;user id=dbuser;password=pass;word" providerName="System.Data.SqlClient" /> 

to

 <add name="db" connectionString="server=local;database=dbanme;user id=dbuser;password='pass;word'" providerName="System.Data.SqlClient" /> 
+12
Nov 19 '17 at 10:31 on
source share

Define the project containing the DbContext class as the launch.

I was getting this error when calling enable-migrations . Even if I selected the correct Default project in the Package Manager Console , he still looked at the web.config file of this startup project, where there was no connection string.

+10
May 24 '16 at 10:04
source share

Make sure the connection string is in this format:

server = FOOSERVER; database = BLAH_DB; pooling = false; Time Time = 60; Integrated Security = SSPI;

If there is no server tag in your line, then the method will return with this error.

+4
Sep 16 '13 at 19:38
source share

The link to the full sp path resolves this issue for me:

 var command = new SqlCommand("DatabaseName.dbo.StoredProcedureName", conn) 
+3
Jun 02 '13 at 20:51
source share

Check the connection string, as I forgot to add services.AddDbContext<dbsContext>(options => options.UseSqlServer("Default"));

This causes an error, and here, when I add Configuration.GetConnectionString , then this solves the problem

how is the connection now:

 services.AddDbContext<dbsContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Default"))); 

works fine (this problem is solved for the .net kernel)

+3
Jun 06 '18 at 17:33
source share

I had the same problem. Locally, the site worked fine, but at the azure level this did not work with the message above.

it turns out that the problem was setting the connection string in ctor, for example:

  public DatabaseContext() { Database.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["db"].ConnectionString; } 

NOT working, it will be:

  public DatabaseContext() : base("db") { } 

Beats me ..

+2
Sep 30 '16 at 13:42 on
source share

I solved this by changing the connection string on the publishing settings of my ASP.NET Web Api.

Check my answer to this post: How to fix the error :: The format of the initialization string does not match the specification starting with index 0 ::

+2
May 14 '17 at 16:31
source share

I had the same error. In my case, this was due to the fact that there was no final quote for the password in the connection string.

Changed from this

 <add name="db" connectionString="server=local;database=dbanme;user id=dbuser;password='password" providerName="System.Data.SqlClient" /> 

For

 <add name="db" connectionString="server=local;database=dbanme;user id=dbuser;password='password'" providerName="System.Data.SqlClient" /> 
+2
Aug 17 '17 at 3:47 on
source share

This also happens when you copy a web page from one solution to another, then you run your solution and find out that it has a different connection string name in webconfig. Then you carelessly change the name of the connection string in the property bar in the page design window.

It’s better to just change it in part of the code instead of design.

+1
03 Sep '15 at 5:45
source share

I had the same problem, and finally I was able to solve it as follows:

The problem was determining the connection string in my web.config.

 <add name="DefaultConnection" connectionString="DefaultConnection_ConnectionString" providerName="System.Data.SqlClient"/> 

This worked fine because I used a local database when I was managing users and roles. When I transferred my application to IIS, the local database was not available, in addition, I would like to use my database in SQL Server. Therefore, I modify the connection string above with the following SQL Server DB equivalent:

 <add name="DefaultConnection" connectionString="data source=MY_SQL_SERVER; Initial Catalog=MY_DATABASE_NAME; Persist Security Info=true; User Id=sa;Password=Mybl00dyPa$$" providerName="System.Data.SqlClient"/> 

NOTE. The above also assumes that you are going to use the same SQL server from your local field (in case you include it in your local web.config - that is exactly what I did in my case).

+1
Sep 26 '15 at 7:21
source share

My problem was that I added the database logging code to my constructor for the DB object, and this seemed to cause chaos in my azure deployment profile.

FYI - I simplified this example, in real code it was disabled during production (but still in code)

 public class MyDB : DbContext { public MyDB() { this.Database.Log = x => { Debug.WriteLine(x); }; } } 
+1
Jan 25 '16 at 14:34
source share

I had a typo in the connection strings "Database == PESitecore1_master"

 <add name="master" connectionString="user id=sa;password=xxxxx;Data Source=APR9038KBD\SQL2014;Database==PESitecore1_master"/> 
+1
Apr 26 '16 at 0:52
source share

I had the same problem and found out that when IIS was deployed, the connection strings were not set correctly. they were '$ (ReplacableToken_devConnection-Web.config Connection String_0) when viewing site connection strings in IIS instead of a real connection string. I updated them there, and everything worked as expected

+1
Jan 15 '18 at 12:18
source share

I copied and pasted the connection string configuration into my test project and started to encounter this error. The connection string worked fine in my WebAPI project. Here is my fix.

 var connection = ConfigurationManager.ConnectionStrings["MyConnectionString"]; var unitOfWork = new UnitOfWork(new SqlConnection(connection.ConnectionString)); 
+1
Sep 18 '18 at 18:51
source share

I removed & quot at the end of the connection string and it worked

Instead

 App=EntityFramework&quot; 

Used

 App=EntityFramework; 

Set DefaultConnection as shown below

 <add name="DefaultConnection" connectionString="data source=(local);initial catalog=NamSdb;persist security info=True;user id=sa;password=sa;MultipleActiveResultSets=True;App=EntityFramework;" providerName="System.Data.SqlClient" /> 

Note: connectionString does not include:
| X | Metadata Information: "metadata = res: // * /"
| X | Coded Quotes: "" "

+1
Jun 07 '19 at 11:17
source share

My problem was not that the connection string I provided was incorrect, or that the connection string in app.config that I thought I was using was incorrect, but that I was using the wrong app .config.

0
Jul 23 '19 at 21:05
source share

Sometimes the Sql server service does not start. This may result in an error. Go to Services and start Sql Server. That should make it work. enter image description here

0
Aug 13 '19 at 9:37
source share



All Articles