Entity Framework 4.1 The provider did not return a ProviderManifestToken string Exception - sql-server-2008

I downloaded the Asp.NET MVC 3 EntityFramework Code first sample application in vb.net and modified the connection string as I don't have SQL Server Express Edition to try it with Sql Server 2008 Web Edition
<add name="ApplicationServices"
connectionString="Server=MyPC\Sql2008;Trusted_Connection=True;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
when I try to run the application then ProviderIncompatibleException exception is thrown. And following error is displayed in the browser window.
Server Error in '/' Application.
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: Shared Memory Provider, error: 40 - Could not open a connection to SQL Server)
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.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: Shared Memory Provider, error: 40 - Could not open a connection to SQL Server)
Source Error:
Line 24:
Line 25:
Line 26: #For Each item In Model
Line 27: #
Line 28:
Source File: C:\Documents and Settings\Shishir Shukla\My Documents\Downloads\CodeFirstEFVB\CodeFirstMVC\Views\Blog\Index.vbhtml Line: 26
The connection string which I have used works perfectly with my asp.net webforms application and also Winforms application.
Please help me soon to get rid of this problem as I have just switched to MVC.

The problem was with the connection string , I changed it to this and it worked ..
<add name="DBCon" connectionString="Data Source=.\SQL2008;Initial Catalog=TestDB;Integrated Security=True" providerName="System.Data.SqlClient" />

Can you provide a link to the project you downloaded?
You are using Windows Authentication, does the IIS account have permissions to the db?
Finally, verify your dbContext class is named "ApplicationServices". Otherwise, you may need to use the constructor that takes in a nameOrConnectionString.

Your connection string is a valid SQL connection string, but you need an Entity Framework connection string.
When you create your EF Model, create a new connection string from scratch. That will resolve this issue.
You can look at the new conneciton in your web.config, and you wil see that an Entity connection contains additional metadata as part of the connection string, and wraps the SQL conneciton string.
UPDATE:
A valid Entity connection string will look something like this:
<add name="MyDatabaseEntities" connectionString="metadata=res://*/Models.MyDatabase.csdl|res://*/Models.MyDatabase.ssdl|res://*/Models.MyDatabase.msl;provider=System.Data.SqlClient;provider connection string="data source=SERVER;initial catalog=MyDatabase;persist security info=True;user id=userid;password=password;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
However, you should let Visual Studio build the connection string for you.

Related

NServiceBus .netcore + MySql

I’m trying to configure NServiceBus in a simple .netcore3.1 console application to use MySql.
I have the Persistence set to SqlPersistence with a SqlDialect.MySql and i'm using the SqlServerTransport*.
My connection string is of type MySqlConnection :
server=localhost;user=root;database=database;port=3306;password=password;AllowUserVariables=True;AutoEnlist=false
When I run the application, I get the error :
System.Exception: ‘Pre start-up check failed: Could not open connection to the SQL instance. Check the original error message for details. Original error message: Keyword not supported: **port**
Does anyone have any ideas what it might be? Any help would be great!
FYI. I have efcore up and running using and connecting to the MySql database.
So it turns out I was trying to use the SQL Server transport configured with MySql. This is not supported.
MySql can only be used in the persistence layer.
Particlular Support -
"The SQL Server Transport unfortunately only supports SQL Server.
Unfortunately you’ll have to select another technology to enable
messaging."
Where are you storing your connection string? Could the cause be that you did not specify the correct provider name providerName="MySql.Data.MySqlClient"?
<connectionStrings>
<add name="devConnectionString" connectionString="server=go.itelescope.net;port=3307;user id=xxxxxxxx;password=xxxxx;persistsecurityinfo=True;database=dev"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>

MySql ASP.NET Identity unexpectedly binding to SQL Server under Win10

I have a live web application (ASP.NET 4.5.1, MVC 5.2.3, EF 6.1, MySql 5.1.35) which has worked for months without difficulty hosted on MS Server2008R2(Web).
I am attempting to move my dev environment to a Win10 virtual machine (previously a Win7 VM) and am opening a copy of the live system and replicated DB on the new machine in VS2015.
When running the application (I am using asp.net Identity 1.0 for authentication) I get the following exception in my _layout.vbhtml page:
An exception of type 'System.Data.SqlClient.SqlException' occurred in
System.Web.dll but was not handled in user code
Additional information: 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: SQL Network Interfaces, error: 26 - Error Locating
Server/Instance Specified)
at:
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav" style="width:auto;white-space: nowrap;">
#If (Request.IsAuthenticated) Then
#<li>#Html.ActionLink("Home", "Index", New With {.Area = "", .controller = "Home"})</li>
If **User.IsInRole("Salesman")** Then
It's not surprising that the exception isn't being handled as I'm not using SQLServer...
I'm baffled why the User object (System.Web.Security.RolePrincipal) is using SQLClient rather than MySQLClient as specified:
Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("IMSSecurityEntities")
End Sub
Web.config:
<connectionStrings>
<add name="IMSSecurityEntities" connectionString="data source=localhost;database=db1;Uid=root;Pwd=password;" providerName="mysql.data.mysqlclient" />
The very same project when run in VS2015 on the Server2008R2 machine correctly connects to the MySQL db.
Would asp.net Identity maybe 'fall back' to using SQLServer in certain situations?
Did some more digging and googling and found a solution at: User.IsInRole doesn't work
Adding the following to web.config resolved the issue:
<modules>
<remove name="RoleManager" />
</modules>
RoleManager was defaulting to SimpleMembership. I don't know why this wasn't a problem on one machine but it was on the other but clearly there was ambiguity somewhere and this sorted it.

AppHarbor: Connecting to a MySQL DB via ASP.NET MVC 5 + Dapper

I'm trying to get an application up and running on AppHarbor. It's been smooth sailing for the most part, but today I'm having trouble connecting to my MySQL database.
Using the credentials AppHarbor provided me with, I successfully connected to the mySQL database instance using dbForge Studio Express, created the necessary SQL schema, and populated the tables with data. Now I'm trying to use the following C# code to do a simple query using Dapper:
var sqlConnStringBuilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["AppHarborMySql"].ConnectionString);
using (var db = new SqlConnection(sqlConnStringBuilder.ConnectionString))
{
db.Open();
// Do database query stuff
return result;
}
But this is the error that I'm running into, when I try to open the database connection:
An exception of type 'System.Data.SqlClient.SqlException' occurred in
System.Data.dll but was not handled in user code
Additional information: 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)
This is how I've declared the connection string in Web.config:
<connectionStrings>
<add name="AppHarborMySql" connectionString="server=MYDOMAIN.mysql.sequelizer.com;database=MYDBNAME;uid=MYUSERNAME;pwd=MYPASSWORD" providerName="System.Data.SqlClient" />
</connectionStrings>
Am I missing something obvious? I'm using ASP.NET MVC 5.x and the latest version of Dapper... thanks in advance!
And of course, despite having spent the better part of an hour investigating, I discover the answer immediately after posting the question.
For anyone else who may run across the same problem: I added the MySql.Web NuGet package to my MVC project, added using MySql.Data.MySqlClient; to the top of my page, and then changed my code to point from SqlConnection to MySqlConnection. Here's what my working code block now looks like:
using (var db = new MySqlConnection(ConfigurationManager.ConnectionStrings["AppHarborMySql"].ConnectionString))
{
db.Open();
// Do database query stuff
return result;
}

How to sync a remote ASP site with local copy of the site?

I copied an entire ASP site from a remote server to my local machine. I can access the homepage, but once I try to login to the rest of the site, I receive the following error:
"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: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)"
I set things up to allow for remote connections (enabling TCP/IP and Named Pipes), but is the problem because I'm trying to access a remote database? The connection string in Web.Config is:
<connectionStrings>
<add name="ISBEPI_DEV" connectionString="Data Source=ERI-DB-06\DEVELOPMENT;
Database=ISBEPI_DEV; Initial Catalog=ISBEPI_DEV;Persist Security Info=True;
User ID=Pi_usr; Password =J6$h3Qoz#9Yw;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Any help would be very much appreciated! Please let me know if I can provide more info. Thanks!
Looks like you specified incorrect connection string or you are not allowed to connect to that SQL server. Have you tried to connect to that database from SQL Management Studio or Server Explorer in Visual Studio?

error: 26 - error locating server/instance specified

This is Arun from Chennai. I have developed my first application in WPF (C#) with VS 2008 & SQL Server 2008. It works fine in my system. After deployment, it wont works in other systems. It shows the following error message.
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 instance name is correct and sql server is configured to allow remote connections.(provider: sql network interfaces, error: 26 - error locating server/instance specified).
I have gone through the google and done the following steps but no use.
Server Name : ECARE432\SQLEXPRESS
Instance Name : SQLEXPRESS
App.Config have:
<connectionStrings>
<add name="TimeTracker.Properties.Settings.myecareConnectionString" connectionString="Data Source=ECARE432\SQLEXPRESS;Initial Catalog=myecare;Persist Security Info=True;User ID=sa;Password=ecare123#" providerName="System.Data.SqlClient"/>
</connectionStrings>
Visual Studio-->Tools-->Options-->Database Tools-->Data Connections-->
Changed "SQL Server Instance Name" from "sqlexpress" to blank.
Configuration Tools->SQL Server Configuration Manager->SQL Native Client Configration
Aliases->
Alias Name -> ECARE432\SQLEXPRESS,1433
Port Number -> 1433
Protocol -> TCP/IP
Server Name -> ECARE432\SQLEXPRESS
SQL Server Browser is running in my system.
Server Name is correct. No typo mismatch.
Client machine is able to ping my machine.
TCP 1433 and UDP 1434 Exception added to Firewall. Also Turned off the Firewall in both my system and the client system.
Please guide me how to fix this issue.
I have removed the instance name in the connection string. Just I have changed the "Data Source=ECARE432\SQLEXPRESS;" into "Data Source=ECARE432" in the app.config connection string. It works now.