Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Check your connection string. If you need help with it check Connection Strings, which has a list of commonly used ones.

Commonly used Connection Strings:

SQL Server 2012

Standard Security

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

Trusted Connection

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

Connection to a SQL Server instance

The server/instance name syntax used in the server option 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;

Trusted Connection

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

Connection to a SQL Server instance

The server/instance name syntax used in the server option 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;

Specifying 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;

This might help someone.. My password contained a semicolon so was facing this issue.So added the password in quotes. It was really a silly 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" />

Set the project containing your DbContext class as the startup project.

I was getting this error while calling enable-migrations. Even if in the Package Manager Console I selected the right Default project, it was still looking at the web.config file of that startup project, where the connection string wasn't present.


Check your connection string like I forget to add services.AddDbContext<dbsContext>(options => options.UseSqlServer("Default"));

It causes the error and here when I add Configuration.GetConnectionString, then it solves the issue

like now the connection is:

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

works fine (This problem is solved for .net core)


Make sure that your connection string is in this format:

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

If your string is missing the server tag then the method would return back with this error.


I had the same problem. Locally the site ran fine, but on azure it would fail with the message above.

turns out the problem was setting the connectionstring in the ctor, like this:

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

Does NOT work, this will:

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

Beats me..


Referencing the full sp path resolved this issue for me:

var command = new SqlCommand("DatabaseName.dbo.StoredProcedureName", conn)