Strange MVC Error Using GearHost - asp.net-mvc-4

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.

Related

ArgumentException: Keyword not supported: 'server'

I have an Asp.net MVC5 application and have published it to Microsoft Azure. I first migrated my .mdf files toSql Azure Databases. The database connection string provided in the Azure Portal is not working.
[ArgumentException: Keyword not supported: 'server'.]
My connection string is as follows web.config
connectionString="
Server=tcp:dbprojectserver.database.windows.net,1433;
Initial Catalog=db_project;
Persist Security Info=False;
User ID=username#servername;
Password=kenth&&123;
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=30;
"
I believe so there is something wrong with this connection string. Any help regarding that is highly appreciated.
EDIT
Reading from here SQL Server Connection Strings and following EF Db first or Model first connection string example
<add name="ConnectionStringName"
providerName="System.Data.EntityClient"
connectionString="metadata=res://*/ ContextClass.csdl|res://*/ ContextClass.ssdl|res://*/ ContextClass.msl;provider=System.Data.SqlClient;provider connection string="Data Source=ServerName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True"" />
This is what I am using according to above example
<add name="ProjectEntities" connectionString="metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:dbprojectserver.database.windows.net,1433;Integrated Security=False;User Id=username#servername;Password=kenth$$123;MultipleActiveResultSets=True"
" providerName="System.Data.EntityClient"/>
It says
Keyword not supported 'data source'
I had the same problem when specified EF connection string on the Azure Portal in Application Service settings (Application settings -> Connection strings).
To fix it:
Replace " with "
Specify connection string type as Custom but not as SQL Database.
Also, as I can see you do not have Initial Catalog in your latest example. You need to add it and specify your database in this parameter.
Finally your connection string for application settings in Azure portal should look like this:
metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=tcp:dbprojectserver.database.windows.net,1433;Initial Catalog=<your database>;Integrated Security=False;User Id=username#servername;Password=kenth$$123;MultipleActiveResultSets=True";

Database connectionstring windows authentication but passing user and password

I need some help.
I'm trying to connect to my database.
This is my connectionstring :
<add name="DefaultConnection" connectionString="Data Source=KBV-SQL12-TEST\KBSQLSPTEST; Initial Catalog=KBSPT_aspnetmembership; User Id=KBOVDM01\KBSPT_EXTRANET; Password=SPExtr#n3t" providerName="System.Data.SqlClient" />
The user is an Active Directory user.
When I go to my SQLServer and log on as KBSPT_EXTRANET, I can op the SQL Management Studio and connect to the database.
But in my application when I use the connectionstring mentionned above, I keep getting the message "Underlying provider failed on open".
What am I doing wrong?
You are trying to use a Windows account when the connection string is expecting a SQL Server user account.

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.