Connection string - Keyword not supported: 'initial catalog'
I ran into the error in one of the IdentityServer quickstarts.
Had to replace
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
With
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
Using
Microsoft.EntityFrameworkCore.SqlServer
Because obviously my DB was a Microsoft SQL Server and not SQLite.
check here: Database.OpenConnectionString Method (String, String)
try to specify the provider name as second parameter, from the MSDN example:
var connectionString = "Data Source=.\\SQLExpress;Initial Catalog=SmallBakery;Integrated Security=True";
var providerName = "System.Data.SqlClient";
var db = Database.OpenConnectionString(connectionString, providerName);
You can use the below code
Config file :
<connectionStrings>
<add name="con" connectionString="Data Source=ServerName;Initial Catalog=master;Integrated Security=SSPI;" providerName="System.Data.SqlClient"></add>
</connectionStrings>
cshtmlfile :
var db = Database.Open("con");
var selecteddata = db.Query("select * from movie");
ARRRRHHHHHH!!!!! This is the second time I've run into this, grrrh - wasted hours on it.
Error:
The server encountered an error processing the request. The exception message is 'Keyword not supported: 'initial catalog;MyDatabase;data source'.'. See server logs for more details. The exception stack trace is:
Stacktrace:
at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) at System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential)
This was my faulty connection string:
<add name="Production" connectionString="Password=Secret;Persist Security Info=True;User ID=MyUserID;Initial Catalog;MyDatabase;Data Source=aquickborwnfoxjumpedover.us-west-2.rds.amazonaws.com,1433" providerName="System.Data.SqlClient" />
Looks good right? WRONG
Eventually I spotted the semi-colon here:
Initial Catalog;MyDatabase
To correct it, I used an equal sign:
Initial Catalog=MyDatabase
The correct connection string:
<add name="ConnString" connectionString="Password=Secret;Persist Security Info=True;User ID=MyUserID;Initial Catalog=MyDatabase;Data Source=aquickborwnfoxjumpedover.us-west-2.rds.amazonaws.com,1433" providerName="System.Data.SqlClient" />