Entity Framework with MySql Exception - "The underlying provider failed on Open." - "Reading from the stream has failed." - mysql

We have an application that uses .NET Entity Framework 4 to connect to MySql. I've now set this up on several development machines (Windows 7) and am now deploying to Windows 2008 R2, but an exception is thrown when trying to access the database from the application.
There are two connection strings, one for use with ADO.NET and one for Entity Framework.
We are using MySql connector for .NET v 6.4.4
The exception is:
"The underlying provider failed on Open." - "Reading from the stream
has failed."
When googling the exception, most posts relate to the use of Entity Framework with SqlServer, and in these cases the problem looks to be authentication related. Since we are connecting here with the root user credentials, If this is an authentication issue, I'm not sure how to diagnose. Other applications connect to the database with the same credentials.
The connection strings are:
<add name="AppEntities" connectionString="metadata=res://*/OrmApp.AppEntities.csdl|res://*/OrmApp.AppEntities.ssdl|res://*/OrmApp.AppEntities.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;User Id=root;password=*********;Persist Security Info=True;database=app_staging;Convert Zero Datetime=True"" providerName="System.Data.EntityClient" />
<add name="AppAdoNet" connectionString="server=localhost;User Id=root;password=*********;Persist Security Info=True;database=app_staging;Convert Zero Datetime=True" providerName="System.Data.MySql" />
If anybody has experience of such an issue on MySql or can advise on how to diagnose the issue which I am presuming is at the database end, that would be appreciated.

Strange issue in the end. Answered here http://www.randombytes.me/2012/06/mysql-connector-net-reading-from-stream.html
Updated post link.
Summary:
The production server was using IIS setting 'Enable 32 bit applications' set to 'True', reverting to 'False' resolved the issue. Obviously you'll need to to check if another component in your application requires this flag set 'True'.

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>

SQL Server 2008 Connection Error "No process is on the other end of the pipe"

Let me begin by saying, I am aware of this thread and others around the web that seek to trouble shoot this issue.
The solutions posted there do not apply to my issue. I have spent 5 hours trying to resolve this before deciding to ask the question.
The problem:
When I attempt to log into SSMS (or connect from a java application) using SQL Authentication I get this error:
A connection was successfully established with the server, but then an
error occurred during the login process. (provider: Shared Memory
Provider, error: 0 - No process is on the other end of the pipe.)
(Microsoft SQL Server, Error: 233)
Although it does work, it is not an option for me to use integreated authentication.
The database I am attempting to connect to is on the same machine as my SSMS instance. There is no network, this is a stand-alone system.
NAMED PIPES is ENABLED in my configuration, I HAVE rebooted since, TCP IP is a higher priority than named pipes in my configuration.
I have even gone as far as to uninstall SQL Server and reinstall it, to no avail.
The details of my SQL Server instance are as follows:
Microsoft SQL Server Management Studio - 10.0.2531.0
Microsoft Analysis Services Client Tools - 10.0.1600.22
Microsoft Data Access Components (MDAC) - 6.1.7601.17514
Microsoft MSXML - 3.0 5.0 6.0
Microsoft Internet Explorer - 9.0.8112.16421
Microsoft .NET Framework - 2.0.50727.5466
Operating System - 6.1.7601
Configuration details are as follows:
http://i45.tinypic.com/vxdz7c.png
http://i45.tinypic.com/vxdz7c.jpg
I connect from java using this code.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost;database=AdventureWorks;integratedSecurity=false;User=JIMBO; Password=JIMBO;";
Connection con = DriverManager.getConnection(connectionUrl);
But please remember, this error also occurs when I atttempt to log in to SSMS directly.
Thanks in advance.
-Jim
To force TCP/IP being used replace localhost with 127.0.0.1 in your connection string.
As you are using a username and password make sure SQL authentication is enabled. By default only Windows integrated is enabled on sqlserver 2008.
With SqlServer authentication keep in mind that a password policy is in place to enforce security.
Forcing the TCP/IP connection (by providing 127.0.0.1 instead of localhost or .) can reveal the real reason for the error. In my case, the database name specified in connection string was incorrect.
So, here is the checklist so far:
Make sure Named Pipe is enabled in configuration manager (don't forget to restart the server).
Make sure SQL Server Authentication (or Mixed Mode) is enabled.
Make sure your user name and password are correct.
Make sure the database you are connecting to exists.
My resolution was to login using the Windows Login then go to security>Logins locate the troubled ID And retype the used password. The restart the services...
Adding "user instance=False" to connection string solved the problem for me.
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/Models.Northwind.csdl|res://*/Models.Northwind.ssdl|res://*/Models.Northwind.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS2008R2;attachdbfilename=|DataDirectory|\Northwind.mdf;integrated security=True;user instance=False;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
This problem was caused for me by this error which appeared just prior in the application error log.
"A read operation on a large object failed while sending data to the client. A common cause for this is if the application is running in READ UNCOMMITTED isolation level. This connection will be terminated."
I was storing PDFs in a SQL table and when attempting to SELECT from that table it spit out that error, which resulted in the error mentioned in your question.
The solution was to delete the columns that had large amounts of text, in my case Base64 encoded files.
perhaps this comes too late, but still it could be nice to "document it" for others out there.
I received the same error after experimenting and testing with Remote Desktop Services on a MS Server 2012 with MS SQL Server 2012.
During the Remote Desktop Services install one is asked to create a (local) certificate, and so I did. After finishing the test/experiments I removed the Remote Desktop Services. That's when this error appeared (I cannot say whether the error occured during the test with RDS, I don't remember if I used/tried the SQL Connection during the RDS test).
I am not sure how to solve this since the default certificate does not work for me, but the "RDS" certificate does.
BTW, the certificates are found in App: "SQL Server Configuration Manager" -> "SQL Server Network Configuration" -> Right click: "Protocols for " -> Select "Properties" -> Tab "Certificate"
My default SQL Certificate is named: ConfigMgr SQL Server Identification Certificate, has expiration date: 2114-06-09.
Hope this can give a hint to others.
/Kim
For me it was because only Windows Authentication was enabled. To change security authentication mode. In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties. On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
Change Server Authentication Mode - MSDN - Microsoft
https://msdn.microsoft.com/en-AU/library/ms188670.aspx
This Might help as reference
I had the same issue, after multiple trial of suggested solution on this site and others, I found a solution for my scenario. The account was locked out
How to Check if the account is Locked out...
Login to the server using higher privileged account (like SA or admin rights)
Expand security ==> select the login name ==>open the property window of the login ==> select the status page on the property window
Make sure This 3 Things
1, permission to connect database is GRANTED
2, Login is ENABLED
3, Status
SQL server authentication
Login is not locked out (Uncheck the box)
Thanks
Tsige
I just executed connection.close() by adding it as first statement and it was solved. Then i removed the line.
One follow up to this. I had installed SQL Server 2014 with only Windows Authentication. After enabling Mixed Mode, I couldn't log in with a SQL user and got the same error message as the original poster. I verified that named pipes were enabled but still couldn't log in after several restarts. Using 127.0.0.1 instead of the hostname allowed me to log in, but interestingly, required a password reset prompt on first login:
Once I reset the password the account worked. What's odd, is I specifically disabled password policy and expiration.
Another cause is if the user's default database is unavailable.
I had an account that was used for backing up two databases. When the backup user's default database was taken off-line, the "no process on the other end of the pipe" error started.
Came here looking for a solution to a similar issue, which I just introduced by changing Schannel settings of our IIS server using "IIS Crypto" by Nartac... By disabling the SHA-1 hash, the local SQL Server was not able to be reached anymore, even though I didn't use an encrypted connection (not useful for an ASP.Net site accessing a local SQL Express instance using shared memory).
Thanks Count Zero for pointing me in the right direction :-)
So, lesson learned: do not disable SHA-1 on your IIS server if you have a local SQL Server instance.
For me the issue seems to have been caused by power failure. Restarting the server computer solved it.

use of universal providers and mysql

I created an asp.net mvc 4 application, and added universal providers, because I need to create a custom membership provider that read users data from a my sql database.
When I work on the developer workstation it's all ok, but when I deploy on the server, where there is not Sql Server installed i receive an error. trying to open DefaultConnection.
In the InitializeSimpleMembershipAttribute that is created from the wizard, I have this:
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: false);
this call initialize the db connection, do nothing, and is not used by the custom membership provider, but must be done at startup.
the connection string is:
add name="DefaultConnection" connectionString="Data Source=...;Initial Catalog=...;User id=...;Password=..." providerName="System.Data.SqlClient" />
the problem is that I don't know how to configure to use a mysql db and pass this control in the startup of the application.
If I have to install it in a server with Sql server installed, I configure it properly, and after the initial call the mysql membership provider works without problem, but i have problems when i cannot use this workaround, and exception is raised at the call to InitializeDatabaseConnection.
How can I fix this problem?

The provider did not return a ProviderManifestToken string error

I am trying to create a web app using ASP.Net MVC3, Entity Framework and MySQL.
I have added the following code to my Web.Config file.
<connectionStrings>
<add name="ContactContext" connectionString="server=localhost;database=contacts;uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
I also have created "Person" Model , "ContactContext" in the project "Contact_Me". When I try to create a "ContactController" including Person Model and Contact context, it gives me the following error
"Unable to retrieve metadata for "Connect_Me.Models.Persons". The
provider did not return a ProviderManifestToken string"
MYSQ & MVC3 SQL connection error \ ProviderManifestToken but I am using MySQL, this is the closest question to mine. But the answer didn't solve my problem.
Thanks in advance
I know this may be very basic for a couple of you guys, but this exception is also thrown in cases where EF is unable to locate a Connection String to use.
If you-re working in a multi-layered application, make sure the connection String is added to your client application, instead of the class library that contains you data access code.
Just my 2 cents.
I got this error when my sql server was actually down. So, please be sure that your sql server is up and running.
You can also get this error if you upgrade Nuget references in an EntityFramework project that uses MySql.Data.Entity (latest version is 6.10.X) and MySql.Data (latest version is 8.0.X). Those version numbers should match. You should use the MySql.Data.EntityFramework package with MySql.Data version 8.0 and after, and the MySql.Data.Entity package with versions 6.10 and before.
There are a lot more details in this blog post: https://davidsekar.com/asp-net/mysql-error-the-provider-did-not-return-a-providermanifesttoken
The problem was with the MySQL connector/Net.
I previously used MySQL connector/Net 6.3.5 and after I uninstalled it and installed MySQL connector/Net 6.5.4 the issue was fixed. You can find latest connectors at http://www.mysql.com/products/connector/
Sometimes this issue arises because of sslmode as well, For me the solution was to add sslmode=None to connection string
I had to make a small change to my connection string from
<add name="Connection" connectionString="Server=SOMEHOST;Database=DB;Uid=USR1;Pwd=PASS1;" providerName="MySql.Data.MySqlClient" />
to
<add name="Connection" connectionString="Server=SOMEHOST;Database=DB;Uid=USR1;Pwd=PASS1;sslmode=None;" providerName="MySql.Data.MySqlClient" />
May be the error is in your connection string. Have you tried to connect to your DB instance using the above log in. try changing the connection string
connectionString="Data Source=.;Initial Catalog=contacts;Integrated Security=True uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
use above if you are using sql server, else if you are using sql express use below one
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=contacts;Integrated Security=True uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
Even though this is answered, but I have experienced the same problem and my in case it was in the connection string; I had the part "Integrated Security" when I really shouldn't have used it; I was relying on the database authentication.
I removed the "Integrated Security=True" part and it worked perfectly :)
Restarting the computer worked for me.
While this message was showing, I did not find any differences between my computer [Windows 10] and the test server where the the application was deployed with the same configuration and was working correctly there and using the same database. It means the issue was probably not connected to the database running on the test server.
Worth mentioning is there were some Windows updates pending while restarting.

A transport-level error has occurred... (Existing connection closed by the server) Sql Server 2008

I have a web application which is currently running on Windows XP operating system with SQL Server 2005 database and IIS 6.0.
Now, we are trying to upgrade it to IIS 7.0 on Windows Server 2008 and SQL server 2008 database.
When I run the application then it is throwing "A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)" randomly at different database calls.
I have verified using "sp_who" that only one connection which I am using is opened.
Can anyone tell me, what could be the cause of this issue?
This blog post by Michael Aspengren explains the error message "A transport-level error has occurred when sending the request to the server."
Maybe the database is set to auto-close? This used to be the default for databases created on the older MSDE/Express edition.
ALTER DATABASE YourDatabaseName SET AUTO_CLOSE OFF;
More:
The SQL Server 2005 Express Edition Overview states:
Features like Auto-Close and the ability to copy databases as files are enabled by default in SQL Server Express ...
I can't remember which service pack changed the default, but the New Database UI in the SP3 version of Management Studio Express defaults the Auto Close setting to false.
This is an error that occurrs when connecting to database due to a lower layer network-related error that you cannot handle from Sql Server.
It would be great that the API used to conenct handled this error but AFAIK it is not. The only way to solve this is to retry connecting to the database when this error occurrs.
You should try to reconnect at least a couple of times more to get sure that the error is not persistent and if it is the case then throw the exception. My experience tells me that trying to reconnect, the 99.9% of times you will succed.
Often, it's the database being offline/closed or the SQL Instance being restarted/offline
In my case. We have DELL R720, NICs are on board and PCI Broadcom NetXtreme Gigabit Ethernet cards. We run into two issues.
Network speed is very slow for HyperV VMs. The solution is to disable the "Virtual Machine queues" of the HyperV host Broadcom nic property windows. It is in the Advanced tab.
SQL client having this transport level issue. It only happened once in every 10-15 min. At the same time the RDP service kick out client from time to time also. The solution is to disable the "Large Send Offload V2" of the HyperV host Broadcom nic property windows. It is in the Advanced tab.
Check if you have MultipleActiveResultSets=true; set in your connection string.
Transport level errors are often linked to the connection to sql server being broken ... usually network.
Timeout Expired is usually thrown when a sql query takes too long to run. Is this the scenario in your case? Like stored proc taking too much time to execute or are there are batch jobs that are executed?
Use clearpool(urSQLconnection), along with dispose. This will clear the dirty connection. and you can open new connection.
Got this trying to execute commands from multiple threads on one connection object in .net, that was a stupid mistake. Locking it or using a separate connection per thread fixes that.
In my case it was McAffee that was pre-installed. Can tell if it was conflict with other solutions or not. The connection was on VPN, on WiFI. Maybe this will help someone in future.