I have an azure website and database. I'm running an ASP.NET MVC 4 / EF 5 app localy and trying to put some data to the azure database before to deploy the app. But I have a TargetInvocationException : {"The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588"}
Keyword not supported : server
This is the connection string that I get from my azure dashboard :
<add name="myconstring" connectionString=Server=tcp:myserver.database.windows.net,1433;Database=mydatabase;User ID=cdptest#myserver;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.EntityClient" />
I tried this I got "Keyword not supported : data source"
<add name="myconstring" connectionString="Data Source=myserver.database.windows.net;Initilal Catalog=mydatabase;User ID=cdptest#myserver;Password=*****;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.EntityClient"/>
The following works for me:
<add name="coupdpoAPEkowswAEntities" connectionString="Server=tcp:myserver.database.windows.net,1433;Database=mydatabase;User ID=cdptest#myserver;Password=*****;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.EntityClient"/>
Use Server instead of Data Source, and specify the protocol and the port, and use Database instead of Initial Catalog
OK the providername was wrong. System.Data.SqlClient was excepted as this is a code first app model.
I probably got System.Data.EntityClient from another app with Model First or Database First...
Related
I am trying to create an App Service web app in the Azure Portal and to connect the web app to my local on-premises SQL Server database using the new Hybrid Connection feature.
Created a simple ASP.NET application using Visual Studio 2015 and trying to connect to the SQL server Database which is on on-prem. And modified the connection String as follows
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=PRAVEEN,1433; User ID=sa; Password=my_password;"
providerName="System.Data.SqlClient" />
</connectionStrings>
When the application is started its running without any errors as shown in below screenshot1.
But when I try register (enter any record) it throws me with an error as specified in the below Screenshot3....
"https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-connect-on-premises-sql-server/" - this is the documentation to which I'm referring to..
So, can anyone from the other end help me out please...
Microsoft SQL Server Management Studio screenshot....
Thank you..
#Praveen,
It is what it says - meaning Initial Catalog is missing in your connection string. It requires the Db name to connect to. You have the servername, SQLUserName, SQLPassword, but missing the DatabaseName it requires. Please change your connection string to include the the DbName as follows
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=YourServerName,1433;Database="YourDbName" UserID=YourId;Password=YourPswd;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Look at this site to configure your connection string appropriately: http://www.connectionstrings.com/store-connection-string-in-webconfig/
I have spent several hours trying to search this on the web in addition to calling and emailing support at 1and1.com web hosting with no success.
I have ASP.NET pages which connect to MS SQL Server database using the entity framework. On my local machine, all works fine (naturally). However, when I modify the connection string in my web.config to point to my SQL Server database on 1and1.com, I get the following error:
"Unable to load the specified metadata resource."
Here's my current connection string (as defined in my web.config file):
<add name="TimeDataLicenseEntities"
providerName="System.Data.EntityClient"
connectionString="metadata=res://*/
Model1.csdl|res://*/
Model1.ssdl|res://*/
Model1.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=dbXXXX.db.1and1.com,1433;
Integrated Security=false;
initial catalog=database_name;
user id=dboXXXX;
password=valid_password;multipleactiveresultsets=True"" />
(Please note that where there are 'XXXX' the values are different in the actual config file as well as for 'database_name' and 'valid_password')
I'm using the Entity Framework in the code so I'd prefer solutions that correct the content of my web.config file.
Here is what ended up working for me:
<add name="TimeDataLicenseEntities"
providerName="System.Data.EntityClient"
connectionString="metadata=
res://<assemblyname>/Model1.csdl|
res://<assemblyname>/Model1.ssdl|
res://<assemblyname/Model1.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=dbXXXX.db.1and1.com,1433;
Integrated Security=false;
initial catalog=database_name;
user id=dboXXXX;
password=valid_password;
multipleactiveresultsets=True"" />
By including the assemblyname for my code in the sections above (the brackets ('<' and '>') should not be included), I was able to finally get it to work.
Thanks all for your assistance.
Here is what actually works on 1and1 server from ASP.NET Code first design. So, simply replace your serverName, DatabaseName, UserID, and Password.
<add name="DefaultConnection"
connectionString="Data Source=dbXXX.db.1and1.com,1433;Initial Catalog=dbYYYYY;Integrated Security=False;user id=dboZZZZZ;password=YOURDBPASSWORD;MultipleActiveResultSets=True;Application Name=EntityFramework"
providerName="System.Data.SqlClient" />
Hope this can help anyone looking to use 1and1 asp.net server since their customer service is pretty useless.
How can I use an .mdf file (called SQL Server Database in VS2012) for Entity Framework?
I get this error message:
Invalid value for key 'attachdbfilename'.
This is my connectionstring:
<add name="DbContainer" connectionString="metadata=res://*/Database.Db.csdl|res://*/Database.Db.ssdl|res://*/Database.Db.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDb)\v11.0;initial catalog=DataContext;Integrated Security=True;AttachDBFilename=|DataDirectory|\DataContext.mdf;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />.
In Global.asax.cs, Application_Start I set the correct path for |DataDirectory| like this:
string newPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data");
AppDomain.CurrentDomain.SetData("DataDirectory", newPath);
Do any of you know to make this work?
Btw. it works when running my web application locally (i.e. debug), and does not work when publishing to my online domain.
If it works locally but not online, the problem is from data source part of your connection string. And if you want to attach your db at runtime, not by management studio, remove the initial catalig part. So change it to something like the following:
<add name="DbContainer"
connectionString="metadata=res://*/Database.Db.csdl|res://*/Database.Db.ssdl
|res://*/Database.Db.msl;provider=System.Data.SqlClient;
provider connection string="data source=RemoteServerInstance;
Integrated Security=True;AttachDBFilename=|DataDirectory|\DataContext.mdf;
MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
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>
Im trying to user ASP.NET MVC3 with Entity Framework and ASP.NET Membership for authentication. I've set up an existing database as my application services database for membership.
When i create the entity data model through the wizard it adds the following connection string to my web.config.
<add name="DBEntities" connectionString="metadata=res://*/Models.DB.csdl|res://*/Models.DB.ssdl|res://*/Models.DB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=PM\SQLEXPRESS;Initial Catalog=DB;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
I'm a noob so i don't really understand why but i tried using the same connection string for my membership provider and failed (probably because of this: providerName="System.Data.EntityClient" ?).
So i added a separate connection string to the same database and used it for the membership provider.
<add name="ApplicationServices" connectionString="Data Source=PM\SQLEXPRESS;Initial Catalog=DB;Integrated Security=True" providerName="System.Data.SqlClient"/>
It works fine when i use ASP.NET configuration to add user and etc. But when i run the application and try to do something like validating a user i get an error;
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The handle is invalid.)
I made a guess this has something to do with my connection strings. I'm hoping some of you experts can help. Cheers.
Have you tried restarting the server : A transport-level error has occurred when receiving results from the server ?
Not a solution or an answer, just a pointer to a similar issue..