What does App=EntityFramework do in Sql connection string? - sql

I have 2 connection strings - 1 local and 1 for my main production server. Entity Framework added App=EntityFramework to my local string when I installed it (4.1) - I'm now on 4.3. What does this do - I can't find any reference to it?
Here's my local connection string:
<add name="LocalConnection"
providerName="System.Data.EntityClient"
connectionString="metadata=
res://*/;
provider=System.Data.SqlClient;
provider connection string='
Data Source=.\SQLEXPRESS;
AttachDBFilename=C:\mypath\MyDb.mdf;
Integrated Security=True;
User Instance=True;
MultipleActiveResultSets=True;
App=EntityFramework'" />
Just curious!

App and Application Name are simply a way for somebody debugging SQL Server to know which client is connecting to it. If you had a SQL Server that has several apps that used it, it might be hard to know which one was sending which statements. If each app used a different Application Name it would be very clear.
Check this out for more info.

It's just the synonym of the Application Name.
You can see the Connection String properties outlined here:
http://msdn.microsoft.com/en-gb/library/system.data.sqlclient.sqlconnection.connectionstring.aspx

Related

Strange MVC Error Using GearHost

When I run my program on my local machine it works just fine. However, when I try to interact with my database via GearHost, I get this nugget of an error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified.
Everywhere I have gone, the forums say it is a connection string error.
If that is the case here is my connection string:
<add name="GameStoreEntities" connectionString="metadata=res://*/Models.GamesModel.csdl|res://*/Models.GamesModel.ssdl|res://*/Models.GamesModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\GameStore.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
If anyone has any idea about what is wrong with the connection string, I would appreciate your feedback.
GearHost does not seem to have support for LocalDB.
So you would have to create a database on their admin panel and use the credentials of the default user that is created to write your connection string. You could also create a new user for the database and use those credentials instead.
Either way your new connection string should be something like this
<add name="GameStoreEntities"
providerName="System.Data.SqlClient"
connectionString="Data Source=DATABASEHOST;Initial Catalog=DATABASENAME;Integrated Security=False;User Id=USERNAME;Password=PASSWORD;MultipleActiveResultSets=True" />
where you just replace the DATABASEHOST with the hostname for the database. You would see this at the bottom of the page after creating the database.
You get the PASSWORD by clicking the uncover(eye) button after creating the database
If you have data in the localDB that you want to sync to the database you have created on GearHost you can use the Data Comparison and Schema Comparison tools in Visual Studio to update the target database.

Defining connection string using windows authentication across domains to access SQL server

I have problems defining the connection string in a windows service application. The SQL server and windows service are on different domains, and thats the problem. However, i know this is possible, because when using runas.exe in the terminal with this parameters there is no problem.
%windir%\system32\runas.exe /noprofile /netonly /user:DOMAIN1\%USERNAME% "ssms -nosplash -S SQLServerName -E"
So the problem should be in my connection string. How can i modify my connection string to access the server the same way? My connection string now looks lite this:
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/DataAccess.MyDatabase.csdl|res://*/DataAccess.MyDatabase.ssdl|res://*/DataAccess.MyDatabase.msl;
provider=System.Data.SqlClient;provider connection string="data source=SQLServerName;
initial catalog=MyDatabase;Trusted_Connection=yes;User Id=DOMAIN1\USERNAME;Password=*****;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
UPDATE
Seams like it isnt possible to replicate the runas.exe command exactly. I tried to use impersonation like podiluska explained. But, this only works if the user can run on the current domain. In my case i cant, I want to send the windows credentials as parameters when connecting to the database, because that user cannot log on in the current domain. Can anybody confirm that this is impossible?
You need to use impersonation - either in the IIS app pool, or by adding a line to the web.config
<identity impersonate="true" userName="DOMAIN1\UserName" password="****" />
(and remove the user id / password entries from the connection string

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

I've got an application running on ASP.NET MVC 3 with Entity Framework Code First. In development I was using a SQL Compact database, however upon moving this to my virtual server, I am attempting to target SQL Express.
There were initially issues to do with a "CREATE DATABASE in master" error, which I got around by extracting the model from the SQL Compact database into an SQL script and executing that on the server to create the DB.
I have created a new connection string to point at the SQL Express instance, which uses the EF format:
<add name="LouiseClarkEntities" connectionString="metadata=res://*/Models.LouiseClark.csdl|res://*/Models.LouiseClark.ssdl|res://*/Models.LouiseClark.msl;provider=System.Data.EntityClient;provider connection string="Data Source=.\SQLEXPRESS; Initial Catalog=LouiseClark; User ID=<username>; Password=<password>"" providerName="System.Data.EntityClient" />
The error I am now getting when navigating to a page that uses the DB, is:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
I have installed Entity Framework 4.1 on the server to try and see if this would solve the issue, but it didn't seem to do much good.
Snippet from the stack trace on error page:
[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1420567
System.Data.EntityClient.EntityConnection.GetFactory(String providerString) +35
[ArgumentException: The specified store provider cannot be found in the configuration, or is not valid.]
Any help would be appreciated, as this has been bugging me for days now!
Thanks,
Chris
Use the normal connection string with code first.
<add name="LouiseClarkEntities" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=LouiseClark; User ID=<username>; Password=<password>" providerName="System.Data.SqlClient" />
On your second problem, and partly the cause of the first too...
what you did wrong is which I got around by extracting the model from the SQL Compact database into an SQL script and executing that on the server to create the DB.
You should use migration scripts for that - and use in PM console then Update-Database -Script to dump out what you need - then deploy that to the server Database.
Problem is that there are CF has its own table and data that needs to be initialized properly. If that doesn't match you'll end up with something like that.

login failed connecting to SQL Server with AttachDbFilename and User Instance

I am developing ASP.NET 2.0 application using SQL Express 2005. I have attached my database with the application.
The Connection string:
<add name="WCMIRConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="\App_Data\WCMIR.mdf";Integrated Security=True;Trusted_Connection=no;User Instance=True" />
When trying to connect the following error appears :
Cannot open database "dp-name" requested by the login. The login failed.
Login failed for user 'Machine\useID'.
How can this error be resolved?
First I think the connection string should be with |App_Data| not \App_Data\
Second Make sure that this user has permission on this folder and on this DB
You shouldn't need the AttachDbFileName if your database is already attached, but you should include InitialCatalog to indicate which database you would like to connect to.
Problem Solved
Connection string must be like :
Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|DB.MDF;" +
"Integrated Security=True;User Instance=True";
Just try to use "|" instead of backslash in your code.

SQL Error Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection when I'm trying to open the WebPart

I've created a custom Web Part for SharePoint that interacts with SQL.
Everything worked fine on my DEV server.
After I moved the WebPart to the client's server I started having problems.
I get Error Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection when I'm trying to open the WebPart.
I've searched for solution for a few hours by now and everything I have found doesn't seem to work in my case.
This is how my connection string looks like:
<add name="MyDataEntities" connectionString="metadata=res://*/MyDataModel.csdl|res://*/MyDataModel.ssdl|res://*/MyDataModel.msl;
provider=System.Data.SqlClient;provider connection string="Data Source=ServerName;Initial Catalog=DBName;
Trusted_Connection=yes;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
The SharePoint Web App with the web part and SQL DB are on two different machines.
Here's what I've tried:
1). Made sure SQL uses Mixed mode authentication
2). Made sure the account I'm using has rights to access SQL
3). Tried replacing Integrated Security=True; in the connection string with the User ID = UserID; Password=Password; where UserID and Password were the account IIS is running under.
I ran profiler while clicking on the link and it looks like the app is not using the account’s credentials and is trying to log in anonymously.
Any help is appreciated, I'm desperate because this must be up and running by tomorrow.
Thanks in advance!
Try SPSecurity.RunWithElevatedPrivileges: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
This method will run code as the ASP.Net application pool identity. Wrap your database calls with it.