System.Data.ProviderIncompatibleException in Entity Framework - c#

Is there any thing missing in my connection string so that i am getting this error:
An exception of type 'System.Data.ProviderIncompatibleException' occurred in EntityFramework.dll but was not handled in user code Additional information: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
This is my connection String in web.config:
<connectionStrings>
<add name="OnlineStoreEntities" connectionString="Data Source=SERVERNAME\SQLEXPRESS;Initial Catalog=MVCOnlineShop;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MVCOnlineShop" connectionString="metadata=res://*/Models.ShopModel.csdl|res://*/Models.ShopModel.ssdl|res://*/Models.ShopModel.msl;provider=System.Data.SqlClient;provider connection string="data source=AHMADZAKARIA-PC;initial catalog=MVCOnlineShop;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>

Check your connection string in *.config file and most probably you are missing the providerName="System.Data.SqlClient". See Entity Framework Config File Settings for more information

Related

Server error in ASP.NET application when I am trying to connect to the server

I have a problem with my first ASP.NET webforms app. I'm following a Microsoft tutorial. When I'm running the application to create the database for first time, this error appears in the browser:
Server Error in '/' Application.
Invalid value for key 'attachdbfilename'.
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.ArgumentException: Invalid value for key 'attachdbfilename'.
I'm not sure if my connection string is fine
DESKTOP-6ANEE4G\MSSQLSERVER01 this is the name of my database.
Tutorial: https://learn.microsoft.com/es-es/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/ui_and_navigation
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(DESKTOP-6ANEE4G\MSSQLSERVER01)\v11.0;Initial Catalog=aspnet-WingtipToys;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="WingtipToys"
connectionString="Data Source=(DESKTOP-6ANEE4G\MSSQLSERVER01)\v11.0;AttachDbFilename=|DataDirectory|\wingtiptoys.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

Publishing asp.net mvc application Connection String

I am using Entity Framework in my Application.
I am publishing application for first time to somee.com
But I have the problem with the connection string.
My connection string in web.config
<connectionStrings>
<add name="StoreDBContext" connectionString="metadata=res://*/Models.StoreModel.csdl|res://*/Models.StoreModel.ssdl|res://*/Models.StoreModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\StoreDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="StoreDB" connectionString="metadata=res://*/Models.StoreModel.csdl|res://*/Models.StoreModel.ssdl|res://*/Models.StoreModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\StoreDB.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
and by database connection string on somee database is :
workstation id=storebd.mssql.somee.com;packet size=4096;user id=****;pwd=****;data source=storebd.mssql.somee.com;persist security info=False;initial catalog=storebd
How should I format connection string in web.config file according to database connection provided by some.

App.Config transformation not working

I am trying to change the app.config dinamically on my build server, I created a Configuration called Build, and I have these 4 .config files.
this is my app.config
<connectionStrings>
<!--configSource="connectionStrings.config"-->
<add name="TestContext" connectionString="Data Source=ServerDoesNotExist;Initial Catalog=TestDb; Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>
and on my app.build.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionstrings xdt:transform="Replace">
<add name="TestContext" connectionstring="Data Source=REALEXISTINGSERVER;Initial Catalog=TestDb; Integrated Security=true" providername="System.Data.SqlClient"/>
</connectionstrings>
</configuration>
However when I created the build definition and added the configuration =Build I get this error
Error: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception: The network path was not found
Which means is taking the app.config file and not the transformation
You can use SetAttributes
<connectionStrings>
<add name="TestContext" connectionString="Data Source=REALEXISTINGSERVER;Initial Catalog=TestDb; Integrated Security=true" providername="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
please refer to
How do I use Web.Config transform on my connection strings?

Cannot connect to local DB at another PC. ASP .NET MVC4

I have created an mvc 4 database application on "PC1". I just have chosen by right click "Database SQL Server" and created Entity Framework with Database First approach. It works okay at "PC1". But when I copied my project to another PC, then the project failed.
I do not have an SQL Server at the PC. I just copied the mvc 4 project with local database.
The error is: "...(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
I suppose that I should rewrite connection string. I've done this steps:
http://msdn.microsoft.com/en-us/library/hh873188.aspx
And I have tried to change a connection string from:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-TestApplication-20140918110411;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
To:
I have added name of PC(TomPC) to connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.TomPC\SQLEXPRESS;Initial Catalog=aspnet-TestApplication-20140918110411;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.TomPC\SQLEXPRESS;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.TomPC\SQLEXPRESS;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
However, it fails with the same error.
I would greatly appreciate any help!
You will also need to ensure that TCP/IP is enabled in SQL Server config on TomPC, and also open up port 1433 (the default port, but it might be different, e.g. if there's more than one instance of SQL running on that PC).
Data Source=.\SQLEXPRESS
The . means "localhost" or 127.0.0.1
So adding the . means localhost\SQLEXPRESS or 127.0.0.1\SQLEXPRESS
You need to change it to:
Data Source=TomPC\SQLEXPRESS
I've found an answer. The application could not connect as connection string should be modified as LocalDB:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=aspnet-TestApplication-20140918110411;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="CustomerDatabaseEntities" connectionString="metadata=res://*/UserModel.csdl|res://*/UserModel.ssdl|res://*/UserModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\CustomerDatabase.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
http://www.asp.net/mvc/tutorials/mvc-5/introduction/creating-a-connection-string

Insert Error:Directory lookup for the file

I am have a register page on my website built in VS2010 and when I fill the form in a click register I am getting the following error. Help would be appreciated.
System.Exception was unhandled by user code
Message=Insert Error:Directory lookup for the file "C:\Users\myname\Documents\myname\Project\App_Data\SJDatabase.mdf" failed with the operating system error 5(error not found).
Cannot attach the file 'C:\Users\myname\Documents\myname\Project\App_Data\SJDatabase.mdf' as database 'SJDatabase'.
connection string:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
<add name="MyConsString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|SJDatabase.mdf;
Initial Catalog=SJDatabase;
Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
</connectionStrings>
I think you are missing a backslash on |DataDirectory|\SJDatabase.mdf
also, you have Integrated Security=SSPI twice and I dont think you need the AttachDBFileName part
try something more simple like this:
"data source=ServerName;Initial Catalog=SJDatabase;Integrated Security=SSPI" providerName="System.Data.SqlClient"

Categories