Connection string - Keyword not supported: 'start directory'

I use the Webmatrix.data database object to create a database connection, however I do not like my connection string. I run it from MVC ASP.net.

Ive tried changing it to server / database, but still the errors are the same. Where am I going wrong?

using (var db = Database.OpenConnectionString(@"Data Source=MY-HP\Serv;Initial Catalog=MyDBSQL;User ID=sa;Password=password")) { var items = db.Query("SELECT * FROM TaskPriority"); } 

Exception Details: System.ArgumentException: Keyword Not Supported: "Start Directory".

+9
asp.net-mvc database-connection connection-string
source share
5 answers

here: Database.OpenConnectionString (String, String) Method

try specifying the provider name as the 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); 
+14
source share

ARRRRHHHHHH !!!!! This is the second time I came across this, grrrh - wasted this time.

Mistake:

The server encountered an error processing the request. Exception message: "Keyword not supported:" start directory, MyDatabase; data source. See Server Logs for more information. Exception stack trace:

Stacktrace:

in System.Data.Common.DbConnectionOptions.ParseInternal (Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) in System.Data.Common.DbConnectionOptions..ctor (String connectionString, Synonyms Hashtable, Boolean useOdc. Data.SqlClient.SqlConnectionString..ctor (String connectionString) in System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions (String connectionString, DbConnectionOptions previous) at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGectionPontConnectionObConnection DocConnectionDbConnectionDbConnectionDbConnection in System.Data.SqlClient.SqlConnection.ConnectionString_Set (DbConnectionPoolKey key) in System.Data.SqlClient.SqlConnection.set_ConnectionString (string value) in System.Data.SqlClient.SqlConnection..ctor (String connectionString, SqlCredential credentials)

This was my erroneous 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 nice? WRONG

In the end, I noticed a colon here:

Start Directory, MyDatabase

To fix this, I used an equal sign:

Start Directory = MyDatabase

The correct connection string is:

<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" />

+11
source share

You can use the code below

Configuration 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"); 
+5
source share

I suggest:


  • You can clearly check your format for the connection string "and". In my case, this is:


  1. You can try creating db again with EF.
0
source share

For me, I got this error because I used a template solution. Without my knowledge, sqlite support is only installed in the template. I had to install Microsoft.EntityFrameworkCore.SqlServer and change the calls in my code from UseSqlite to UseSqlServer .

0
source share

All Articles