Keyword not supported: 'server' - asp.net

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

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="data source=(local);initial catalog=test;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""
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="data source=(local);initial catalog=test;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""
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=....)

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"

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 " by default in your web.config file.
You need to change these back to actual quotes so the connection string can be parsed properly.

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;

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.

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

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.

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

Related

'Connection string "SQLServerConnectionString" was not found.' - Using Azure DB

Basically, I'm busy with a university project and this is the error I keep running into. I've tried multiple solutions from Microsoft's sites, but got nothing.
I added the connection string to my web.config, however, it still doesn't come through for me.
The connection link I took directly off of Azure's connection strings, on the DB I created.
<connectionStrings>
<add
name="SQLServerConnectionString"
connectionString= "Server=tcp:[dblink],1433;Initial Catalog=SACLADB;Persist Security Info=False;User ID=[id];Password=[pass];MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
providerName="System.Data.SqlClient" />
</connectionStrings>
The code used to attempt and connect the database which should use the web.config connection string.
#{
ViewBag.Title = "Papers";
var db = Database.Open("SQLServerConnectionString");
var selectQueryString = "Select * FROM Papers ORDER BY Author";
}
Found the error of my ways;
I was editing the wrong Web.Config. I wasn't editing the one in the root folder where it reads the connection strings, however, all issues are now fixed.

Unable to find the requested .Net Framework Data Provider. It may not be installed

I am having problem in running my ASP.Net MVC project which is an admin project. It connects with a sql server database to fetch record. When I try to build and run, I am welcomed with this error: "Unable to find requested .Net Framework Data Provider. It may not be installed".
Here is the link to this error.
I have tried many solutions available on stackoverflow but none of them worked for me that's why I am posting this question here again. I tried changing the Target Framework version in Properties of project to all the available versions but all in vain. Here is the screenshot of my Global.asax.cs file which is causing this exception.
Below is the connection string of my project:
<add name="AlkhaleejEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=Alkhaleej;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"/>
Connection string provided above indicates EF connection provider being used:
connectionString="metadata=res:///Models.Model1.csdl|res:///Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=Alkhaleej;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"
Note that SimpleMembershipProvider can't use EF provider connection string (see this post) due to usage of SqlClient provider instead of EntityClient, hence it requires SQL Server connection string to interact with database.
Try open Server Explorer => Data Connections => right click your server connection, select Properties => add provided SQL Server connection string something like this one (leave EF connection string part as is, just add SqlClient provider connection string):
<add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=Alkhaleej;Integrated Security=True" providerName="System.Data.SqlClient" />
Then, change connectionStringName parameter on WebSecurity.InitializeDatabaseConnection method inside SimpleMembershipInitializer class to SQL Server connection string name as given below:
public class SimpleMembershipInitializer
{
public SimpleMembershipInitializer()
{
// other code part
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "Email", autoCreateTables: true);
}
}
}
NB: The ideal setup for EF projects should include at least one SqlClient connection string and one EntityClient connection string, which may serve different providers with same target database.
Similar issues:
SimpleMembershipInitializer won't initialize
Unable to find the requested .Net Framework Data Provider. (SqlClient)
Can SimpleMembership and Entity Framework share a connection string?

Connection string in web.config not working

I have a very basic ASP.NET web application that is connecting to a SQL Server database (I am using SQL Server 2008 Express). The problem I am having it is very odd: if I set the connection string for the SqlConnection object directly in code, the application works fine, but if I move my connection string to the web.config file, the application fails.
I show you both the variable and the connection section in the web.config to see if you detect any error:
In the variable:
// works fine
string cs = "data source=.; database=myDataBase; integrated security=SSPI";
SqlConnection conn = new SqlConnection(cs);
Now in the web.config:
<configuration>
<connectionStrings>
<add name="myCS"
connectionString="data source=.; database=myDataBase; integrated security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
...
// Now, if I do this in C#, it does not work:
string cs = ConfigurationManager.ConnectionStrings["myCS"].ConnectionString;
SqlConnection conn = new SqlConnection(cs);
It tells me that there is already a database with that name. Now, I have read things everywhere. Some guy said that instead of using "database" in the connectionString, I could use "initial catalog" and all would be fine. Well, it wasn't fine... I have the same problem... Does anyone know what I am doing wrong? Why is working in one place and not in another? If the connection string was wrong, it should fail in both places, and it is only crashing in the webConfig file... Thanks very much...
If you are running this from Visual Studio, have you tried stopping the Dev Server (running in your system tray) and trying? the Web.config file is normally cached and could cause issues.

ASP.NET EFCodeFirst not using correct connection string

I am trying to publish a website using ASP.NET MVC3 EF and CODEFIRST with a SQL Server 2008 backend. On my local machine I was using a sql express db for development, but now that I am pushing live, I want to use my hosted production database. The problem is that when I try to run the application, it is still using my local db connection string. I have completely removed the old connection string from my web.config file and am using the <clear /> tag before creating the new connection string. I have also cleaned the solution and rebuilt, but somehow it is still connecting to the old db. What am I missing?
This is the new connection string:
<connectionStrings>
<clear />
<add name="CellularAutomataDBContext"
connectionString=" Server=XXX;
Database=CellularAutomata; User ID=XXX; Password=XXX; Trusted_Connection=False"
providerName="System.Data.SqlClient" />
</connectionStrings>
UPDATE
When I debug and look at the DBCONTEXT object, this is what is showing up for its connection:
Data Source=.\\SQLEXPRESS;Initial Catalog=CellularAutomata.Models.D1K2N3CARuleDBContext;Integrated Security=True;MultipleActiveResultSets=True"
I am unsure why this is happening because I cannot find it being set to this anywhere. Also, under configuration it says LazyLoadingEnabled = true, I assume this may be part of the problem, maybe it is not loading the new connection string. Where do I change these parameters?
UPDATE 2
EFCodeFirst is using a default connection string, I can't figure out how to get it to accept the connection string that I specify in the web.config file.
So, When using EF CodeFirst, there is a default connection string that it uses. If you want to be able to use a custom connection string, there are a few parameters guidelines that you must follow.
name ="this must match the name of your database context class"
connectionString="Server=yourserverurl; Database=yourdatabasename; User ID=youruserid;
Password=yourpassword; Initial Catalog=the name of the database to use;
Trusted_Connection=False"
providerName="System.Data.SqlClient"
So far this is working for me.
The connectionString you show is not an EF connection string. The EF won't use it. So you're changing the wrong thing.
An EF connectionString will include providerName="System.Data.EntityClient"
It will look for the same name as your context and depending on what else you
are using other names as well. I usually use the following for controlling
specific features with either the same or specific connection strings
(I keep app services in a different db for example so EFCF can drop tables as needed):
<connectionStrings>
<add name="MyAppContext" .../>
<add name="ApplicationServices" .../>
<add name="DefaultConnection" .../>
</connectionStrings>

ASP.NET A problem when connect from remote DB to localhost instance

I have made the remote database backup (MSSQL Server 2005 Express) to the localhost, and I want to connect with that in my app. To do so, I've changed the connection string:
from
Data Source=190.190.200.100;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
to
Data Source=TOMEK\SQLExpress;Database=myDataBase;User ID=myUsername;Password=myPassword;
but the error appears: Format of the initialization
string does not conform to specification starting at index 0
I can login to the Management studio with that login/pass, and also the user name that I login into sql server has role membership db_owner to that database
what's wrong with that connection string ?
Try one of the 2 options.
Data Source=foo\SQLExpress;Initial Catalog=bar;User Id=user;Password=pwd;
or
Server=foo\SQLExpress;Database=bar;User ID=user;Password=pwd;
They're equivalent, but not sure if you can mix/match
Server/Data Source
Database/Initial Catalog
Are you using a hardcoded string, or from a .config file? Does your username or pwd contain any characters that might need escaping in the .config file? i.e. slash, ampersand?
string connstr = #"Server=foo\SQLExpress;Database=bar;User ID=user;Password=pwd;";
SqlConnection conn = new SqlConnection(connstr);
<add name="ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;Database=bar;User ID=user1;Password=&foo;"
providerName="System.Data.SqlClient" />
Maybe try comparing what you are doing to what is found here:
http://www.connectionstrings.com/sql-server-2005

Resources