Keyword not supported: 'server'
Asked Answered
B

9

34

I've been trying to edit my connection string for uploading my website to a server.
I am not really experienced with this. I got this exception: the Keyword not supported: 'server'.
Here is my connection string:

<add name="AlBayanEntities" connectionString="Server=xx.xx.xxx.xxx,xxxx;Database=AlBayan;Uid=bayan;Password=xxxxx;" providerName="System.Data.EntityClient" />

I've tried embed this string into my old connection string which works very well locally, but it didn't fit : S

Buttonball answered 11/7, 2011 at 7:9 Comment(2)
You didn't say the DBMS you're connecting to.Sumach
marc_s\ yes it's not like the connection string after creating the EDMX, but this is my question, how can I edit it :$Buttonball
B
42

For Entity Framework (database-first or model-first; when you have a physical EDMX model file) you need to use a special type of connection string which is quite different from the straight ADO.NET connection strings everyone else has mentioned so far...

The connection string must look something like:

<add name="testEntities" 
     connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(local);initial catalog=test;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

Inside this connection string, you'll find the provider connection string= attribute which is basically your ADO.NET connection string:

provider connection string=&quot;data source=(local);initial catalog=test;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 

So here, you need to change your server name and possibly other settings.

  • data source=.... stands for your server (you can also use server=.....)
  • initial catalog=..... stands for your database (you can also use database=....)
Blasto answered 11/7, 2011 at 7:41 Comment(2)
@Blasto Where do you get the first connection string fromHoopes
@MohitShah - the UDL trick here worked for me. I took the bit that Filburt generated, and spliced it into the above and it worked like a charm. #10480263Lawannalawbreaker
A
17

In MVC5 using EntityFramework 6.xx and Code First Approach

I had the same problem and I solved this by modifying my providerName

from

 providerName="System.Data.EntityClient"

to

providerName="System.Data.SqlClient"
Amundson answered 11/9, 2016 at 5:46 Comment(0)
D
8

This exception is thrown on azure websites when you store the connection string in the App Service itself (on the 'Application Settings' blade).

If the connection string is an Entity Framework connection string the quotes will be encoded as &quot; by default in your web.config file.

You need to change these back to actual quotes so the connection string can be parsed properly.

Deerdre answered 31/10, 2016 at 19:49 Comment(3)
This was life saving. Thank you very muchMornings
Indeed, double or single tick quotes instead of XML escaping characters workRuthenium
This answer saved my life, simply replace &quote with '(single quote)Hampshire
S
3

I always either run a connection wizard to build my string or I use connectionstrings.com.

Assuming SQL Server:

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

Comparing to yours it is very different.

Server=xx.xx.xxx.xxx,xxxx;Database=AlBayan;Uid=bayan;Password=xxxxx;
Sumach answered 11/7, 2011 at 7:16 Comment(5)
Yes, but again: that's not a valid connection string for EF !Blasto
Thanks, marc, I assumed that the OP could find what he needed at the web site.Sumach
That web site shows straight ADO.NET connection strings - as you did - but not any Entity Framework connection strings, unfortunately...Blasto
@marc I sent them an email asking them to include Entity Framework.Sumach
2023 (12 y later! 😮) -- Server=xx.xx.xxx.xxx,xxxx;Database=AlBayan;Uid=bayan;Password=xxxxx; is now the first one displayed at connectionstrings.comPillsbury
I
3

Same happened to me when using Rider IDE for a .net core 2.2 project. As Rider automatically sets up Sqlite in Startup.cs in the "ConfigureServices" method.

By changing

services.AddDbContext<ApplicationDbContext>(options =>
    options.**UseSqlite**(
        Configuration.GetConnectionString("DefaultConnection")));

into

services.AddDbContext<ApplicationDbContext>(options =>
    options.**UseSqlServer**(
        Configuration.GetConnectionString("DefaultConnection")));

issue was resolved. Of course, first you have to install nuget packages for EF SQLServer and add the connection string to appsettings.json.

Instantaneous answered 30/9, 2019 at 18:12 Comment(0)
S
1

Try this

<add name="AlBayanEntities" connectionString="Data Source=xx.xx.xxx.xxx,xxxx;Initial Catalog=AlBayan;User Id=bayan;Password=1abcd;" providerName="System.Data.EntityClient" />
Salisbarry answered 11/7, 2011 at 7:14 Comment(2)
it throw another exception: Keyword not supported: 'data source'. :$Buttonball
Check this link may be helpful #693999Salisbarry
S
0
EntityConnectionStringBuilder bb = new EntityConnectionStringBuilder();
bb.Metadata = "res://*/dao.bdmi.csdl|res://*/dao.bdmi.ssdl|res://*/dao.bdmi.msl";

//same as below client tobe used
bb.Provider = "MySql.Data.MySqlClient";
MySql.Data.MySqlClient.MySqlConnectionStringBuilder mbb = new MySql.Data.MySqlClient.MySqlConnectionStringBuilder();
mbb.Server = "";
mbb.Database = "";
mbb.UserID = "";
mbb.Password = "";
mbb.PersistSecurityInfo = true;


//use providerconnectionstring insted of connectionstring
bb.ProviderConnectionString = mbb.ToString();
return bb.ToString();

Through this way, you can change your ConnectionString as you want.

Sterling answered 20/3, 2017 at 5:59 Comment(0)
I
0

In my case, I found that my project had the EFSQLLite nuget package installed, which seems doesn't recognise the Server= keyword. I uninstalled that nuget and installed the full EFSQLSERVER one, and it worked fine

Imitative answered 14/10, 2019 at 21:14 Comment(0)
D
0

If you changed your Database from Sqlite to SqlServer. You might run into this error.

Change your connection from

builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlite(connectionString));

to

builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));

Debtor answered 4/7, 2023 at 7:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.