I have an ArgumentException : Keyword not supported: 'metadata'.
I tried many things, read many posts. I dont know what to do...
This is my CS :
<add name="CDPContext"
connectionString="metadata=res://*/CDP_Model.csdl|
res://*/CDP_Model.ssdl|
res://*/CDP_Model.msl;
provider=System.Data.SqlClient
provider connection string='Data Source=(LocalDb)\v11.0;
AttachDbFilename=\CDP.mdf;
Initial Catalog=CDP;
Integrated Security=True;
MultipleActiveResultSets=True;
App=EntityFramework'"
providerName="System.Data.SqlClient" />
Thanks.
the connection string you provided above is for model first.
to use connection string for code first you could write your connection string as below
<add name="CDPContext" connectionString="Data Source=(LocalDb)\v11.0;
AttachDbFilename=\CDP.mdf;
Initial Catalog=CDP;integrated security=True;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
and also go to you context, if there is a throw exception in it, just remove it.
providerName="System.Data.SqlClient" is the wrong provider for DB First
instead use providerName="System.Data.EntityClient" to access the db using the EDM...
Related
im newbie in c# and i want fetch data from mssql local engine with peta poco orm but i get this error
image of error im getting
and here is my connection string of my class library:
<connectionStrings>
<add name="School" connectionString="Data Source= MSSQLSERVER;Initial Catalog=School;user id=sa; Password=1qaz!QAZ;" providerName="System.Data.SqlClient" />
</connectionStrings>
my database name is School, i tried server too, and my server name which i use to connect to ssms is DESKTOP-KVEJKDS
thanks for your help!
Just replace your Data Source name with your Server name:
<connectionStrings>
<add name="School" connectionString="Data Source= DESKTOP-KVEJKDS\SQLEXPRESS;Initial
Catalog=School;user id=sa; Password=1qaz!QAZ;" providerName="System.Data.SqlClient" />
</connectionStrings>
I have two connections in the web.config basically they are calling the same database. I want to manage this in a better manner because change in one config also needs to change the second connection string as well.
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;persist security info=True;user id=test;password=test123;database=db-AUTH" providerName="System.Data.SqlClient" />
<add name="dbEntities" connectionString="metadata=res://*/InsuranceFinderModel.csdl|res://*/InsuranceFinderModel.ssdl|res://*/InsuranceFinderModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=db-AUTH;persist security info=True;user id=test;password=test123;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
My question is, is there any way i can call the connection string into the other connection string.
For example. default connection connection string into db entities something like
<add name="dbEntities" connectionString="metadata=res://*/InsuranceFinderModel.csdl|res://*/InsuranceFinderModel.ssdl|res://*/InsuranceFinderModel.msl;provider=System.Data.SqlClient;provider connection string= DefaultConnection" providerName="System.Data.EntityClient" />
Any suggestions would be appreciated thanks.
You are not obliged to use connection string defined inside app.config(web.config) file for entity connection. You can change entity connection string at runtime. Read this article for that: http://www.c-sharpcorner.com/UploadFile/dacca2/pass-connection-string-in-run-time-to-entity-framework/ .
Also you can get another connnection string and separete every part of connection string( DataBase,DataSource and etc.) using StringConnectionBuilder class https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.initialcatalog.aspx.
The solution is: Get DefaultConnection string and change entity connection at runtime.
In my project, I have upgrade some of the business to DbContext, previous version was on ObjectContext.
I want to have one ConnectionString in web.config for both DbContext and ObjectContext.
<add name="OjContext" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string="Data Source=server-pc;Initial Catalog=db;User ID=sa;password=123;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
<add name="DbContext" connectionString="Data Source=server-pc;Initial Catalog=db;User ID=sa;password=123;" providerName="System.Data.SqlClient" />
You'll want to build your "OjContext" connection object in your code, using the "DbContext" connection string for EntityConnectionStringBuilder.ProviderConnectionString property.
See more here: https://msdn.microsoft.com/en-us/library/vstudio/Bb738533(v=VS.100).aspx
this is my connection string on godaddy hosting. By the way I have my database and membership database I makes security for some pages on my website.
All tables in one database Waves database. I used it to make login page for admin panel for my website but when I try to login and write pass & username it makes error that I write it above and this my connection string in web.config .also i have another 2 connection strings but it works OK, only this connection string is not working.
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=180.000.004.53\SQLEXPRESS;Integrated Security=false;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
User ID=id;Password=Password;Encrypt=False;
providerName="System.Data.SqlClient" />
<add name="WavesEntities"
connectionString="metadata=res://*/App_Code.WaveModel.csdl|res://*/App_Code.WaveModel.ssdl|res://*/App_Code.WaveModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=004.00.004.03;User ID=id;Password=password;Encrypt=False;Connect Timeout=15;Initial Catalog=Waves;Integrated Security=false;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
<add name="WavesConnectionString"
connectionString="Data Source=000.100.10.0;User ID=id;Password=password;Encrypt=False;Connect Timeout=15;Initial Catalog=Waves;Integrated Security=false"
providerName="System.Data.SqlClient" />
</connectionStrings>
After a minor reformatting of your code, it seems pretty obvious that the first connection string is invalid, and may be causing your problem:
This part should presumably be placed within the quotes, and be part of the connection string:
User ID=id;Password=Password;Encrypt=False;
I have been testing out different things and have concluded that the following error is the reason my database will not initialize and throws an exception. The exception occurs when I reference the database and initialize it. My Web.config connection string is fine as you can see. I am using Entity Framework 6, MSSQL, and C#. Any help would be appreciated.
Exception:
Cannot open database \"xxx\" requested by the login. The login failed.\r\nLogin failed for user 'xxxx'.
Connection String:
<add name="WebDBContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=WebDB;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
Code:
private SchoolContext db = new SchoolContext();
public ViewMethod Method()
{
var students = from s in db.Students select s; //EXCEPTION IS THROWN HERE
}
You should mention userid and password in connection string
<add name="WebDBContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=WebDB;Integrated Security=SSPI;User ID=xyz;pwd=top$secret;" providerName="System.Data.SqlClient"/>
Your connection string is not in the format required by EF, it should actually look similiar to this:
<add name="XYZ" connectionString="metadata=res://*/ModEntity.csdl|res://*/ModEntity.ssdl|res://*/ModEntity.msl;provider=System.Data.SqlClient;provider connection string="Data Source=SomeServer;Initial Catalog=SomeCatalog;Persist Security Info=True;User ID=Entity;Password=SomePassword;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
Also use linq query.
var students = db.Students;
<connectionStrings>
<add name="WebDBContext" connectionString="metadata=res://*/Models.ModelName.csdl|res://*/Models.ModelName.ssdl|res://*/Models.ModelName.msl;provider=System.Data.SqlClient;provider connection string="data source=servername;initial catalog=databasename;user id=username;password=password;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
replace the ModelName to your Model and change connections on your db.