User Instance of SqlLocalDb - localdb

I am getting this Exception When I am trying to access database from C#.
My Connection String is
Data Source=(localdb)\v11.0;integrated security=true;User Instance = true;AttachDbFileName=C:\Users\UserName\Desktop\DB\TestDB3.mdf
Exception is
The user instance login flag is not allowed when connecting to a user instance of SQL Server. The connection will be closed.

LocalDB instances are all "User Instances", and there's no need to specify User Instance=true in your connection string, in fact it is not even supported (as you can see). Just remove this part and it's going to work fine.

Just to add some more information. If some how this doesn't work for you and it still complains that its not able to locate server. You will be required to set following two attributes on your application pool identity in applicationHost file
<add name="DefaultAppPool">
<processModel identityType="NetworkService" loadUserProfile="true" setProfileEnvironment="true" />
</add>
where these two attributes are required to make sure your account can start LocalDB server.

Related

Azure Deployment Entity Framework Connection String Keyword not supported: 'metadata'

I have been developing an application locally using asp and entity framework to interact with my database. I am using a model first approach. I want to deploy this app to Azure but I keep getting the error "Keyword not supported: 'metadata'."
Through searching and reading posts like this: Windows Azure, Entity Framework. Keyword not supported: 'metadata'.
I know its an issue with my connection strings but i can't figure out what i'm doing wrong.
Connection string in my local web config:
<add name="BeCivicData" connectionString="metadata=res://*/Models.BeCivicData.csdl|res://*/Models.BeCivicData.ssdl|res://*/Models.BeCivicData.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=BeCivic;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
Generated Connection String for the Azure DB:
Server=tcp:becivicserver.database.windows.net,1433;Initial Catalog=BeCivic;Persist Security Info=False;User ID={MyID};Password={MyPass}5;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
On the Azure Applications settings page i have defined my connection string as both of the above which didnt work so i tried combining them to have the EF meta data (below) but the Azure connection string and that also gave me the Meta Data error:
metadata=res://*/Models.BeCivicData.csdl|res://*/Models.BeCivicData.ssdl|res://*/Models.BeCivicData.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:becivicserver.database.windows.net,1433;Initial Catalog=BeCivic;Persist Security Info=False;User ID={myid};Password={mypass}5;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" " providerName="System.Data.EntityClient"
In my application the EF .edmx file is in a folder named Models.
Both the database element and the code elements deployed separately to azure successfully and now i just need to link them up.
Keyword Not Supported:metadata
When you attempt to use the the connectionstring within the Azure Portal Connection Strings setting, it will get the above error.
So, try to change the type from SQLAzure to Custom.
You could refer to this article to troubleshoot.
To avoid parsing the connection string yourself, you can use the EntityConnectionStringBuilder class the parse the string and retrieve the database connection string from its ProviderConnectionString property.

SQL Azure EF Database First Connection String in Azure Management Portal

I have a site running n Azure, which uses EF Database First model.
If I embed the connection string in the web.config and deploy all is rosy.
<add name="MyEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string='Data Source=my.database.windows.net;Initial Catalog=myTest_DB;User ID=***;Password=***; MultipleActiveResultSets=False'" providerName="System.Data.EntityClient"/>
But, I don't want the connection string in the web.config because it contains credentials.
So I moved it to the connection string area in Azure Properties.
First issue I hit is getting metadata invalid keyword error.
I solved that by changing the type from SQL Database to Custom.
However, I now get this error:
The connection string 'MyEntities' in the application's configuration
file does not contain the required providerName attribute."
I've trawled the web and tried many variations of the connection string but not yet found the correct one.
Note: I guess I could make this an app setting and move the initialisation of the string to code, but even if only for curiosity sake I would like to know how to do it via the portal.
The problem is not the connection string, but the inability to specify the providerName from the portal.
Try publishing with a local or dummy connection string in place, and overwriting it as you have in the Azure Application Settings. See this answer: https://stackoverflow.com/a/18964294/94853

Failing to get EF connection string to work when setup in Azure's management portal?

I am using ASP.NET MVC4 deployed on WebApps, EF6, Azure SQL Database
I have two connectionstrings, one direct to the DB and one that is needed as I am using Entity Framework. If I setup the first via Azure and leave the EF string in web.config, all works fine. Once I try to move the EF connectionstring to Azure, it breaks.
I have tried to follow all the posts on how to setup an EF connection string in Azure Management Portal, and the advice seems to be to use the following:
In Management Portal:
Name:
EFConnectionString
Value:
metadata=res://MyModel/model.csdl|res://MyModel/model.ssdl|res://MyModel/model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:myserver.database.windows.net,1234;Initial Catalog=mydatabase;User ID=Admin#myserver.database.windows.net;Password=12345678"
SQL Database:
Custom
Note:
" is replaced by " in the Azure string.
In Web.config I still need the following:
<add name="EFConnectionString" connectionString="" providerName="System.Data.EntityClient"/>
I have changed certain details in the connectionstring for security reasons, but the true string does work fine in Web.config.
However when I do attempt the above, I get :
The page cannot be displayed because an internal server error has occurred.
Further Log error message:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
Any help appreciated. I am trying to do this to enhance the security of stored passwords for accessing DB on Azures, as I understand that setting them up via the portal encrypts them.
Thanks.
First check your deployment. I've run in a similar problem, and after a couple of hours struggling I found out that I was deploying without actually sending connection strings, falling back to whatever was in the portal config... the others keys in the we.config were being sent over, but the conn strings weren't... after I properly set it up on the portal, everything went back to normal...

The connection string in the application's configuration file does not contain the required providerName attribute

I have a WorkerRole in Azure that's connecting to an MSSQL database (also in Azure, on its own virtual machine -- in other words not an Azure SQL database). The WorkerRole is using EntityFramework (code first).
My connection string looks like this and connections from the worker role works just fine in my development environment:
<add name="MyConnectionString" connectionString="Data Source=mydatabaseserver.cloudapp.net;Initial Catalog=MyDatabase;User ID=MyUser;Password=ThePassword;" providerName="System.Data.SqlClient" />
However, the application throws the error:
The connection string MyConnectionString in the application's configuration file does not contain the required providerName attribute
As you can see, it clearly does contain the providerName attribute. I have checked the obj/Release folder to see the actual configuration file that is published to Azure, and it does contain the attribute as well.
What am I doing wrong?
Never mind. It is in fact working now.
The reason I thought it wasn't working is that there is a delay in how Azure writes Trace data to TableStorage. This led me to believe that the WorkerRole was still throwing the error after updating the connection string, even though it wasn't.

Web app with EF + database first not working on Azure

I have a ASP.NET MVC application which uses EF (v6) as data access layer. My application works fine on IIS Express and also when deployed to the server running IIS 7.5.
The problem is that I'm getting the following exception when I deploy it to Azure (Web Sites).
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
I've searched the web and I made sure my connection string starts with "metadata=" + checked my db context class' constructor to be sure it contains the correct name (in my case it's "name=PsDataEntities"))
My connection string looks like this: <add name="PsDataEntities" connectionString="metadata=res://*/PsDataModel.csdl|res://*/PsDataModel.ssdl|res://*/PsDataModel.msl;
provider=System.Data.SqlClient;
provider connection string="data source=SERVER_NAME;initial catalog=DB_NAME;user id=UID;password=PWD;
MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Anybody had the same problems?
Any help is appreciated
I did a few more tests (like changing metadata in the connection string to use fully qualified names instead of '*') without success, then I decided to set my metadata (regarding .csdl/.ssdl/.msl) programatically with the help from this post. Application now works correctly when deployed to Azure.