when Our WinApp is idle for while around 8-10 minutes ,and try to do something like get list of customers, we got this error "The underlying provider failed on Open"
i use EF6.1 & MSSQL 2008 r2 Here Is my connection string :
<add
name="MISSystemEntities"
connectionString="metadata=res://*/DB_Model.csdl|res://*/DB_Model.ssdl|res://*/DB_Model.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=10.10.0.3\r2;Initial Catalog=MISSystem;User ID=user;Password=pass;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"
/>
Sql Option Auto Close Is Off
Distributed Transaction Coordinator Is Active for Clients "actually We don't use it"
have ping to server without any time aout at the same time that error occurs
test with domain administrator rights and still have problem
also We Test Connection time out and query execute time out with random values:(
Its seems related the connection issue.
Seems like a connection issue. You can use the Data link properties to find if the connection is fine. Do the following,
Create a blank notepad and rename it to "X.UDL" Double click open it, under connections tab choose the server name/enter the name use the correct credentials and DB OK to save it.
Now open the file in Notepad and check, compare the connection string properties with this..
Refer link:- Entity Framework The underlying provider failed on Open
The underlying provider failed on open entity framework
Please read the link
Here is same issue explain to resolve by Microsoft team member.
http://blogs.msdn.com/b/dataaccesstechnologies/archive/2012/08/09/error-quot-the-underlying-provider-failed-on-open-quot-in-entity-framework-application.aspx
my problem (issue) was SQL server Connection pooling :D
the pooling store the last request time and when u idle for while around 5-10 min and then when it receive request it'll answer the request ( !??! ) but after that the pooling terminate your connection and your next request throw the exception :(
for now i set timer to each 30s send a request to DB !
i was using entity framework 6 with wcf web service with "integrated security=true" in the wcf web.config. the error message was similar. what was happening, iis was using the application pool credentials to connect to the database. once i specified a user account in the connection string, it worked like a charm...
hope this helps.
Related
I've being trying in vain to solve a problem on a newly created windows server with IIS hosting an ASP.NET application that was copied from another environment. The issue is that I cannot manage to connect to the database when the application tries to open a connection via entity framework.
If this is off topic for SO let me know so I can move to another channel, I thought it belonged here as seems specific to EF.
In detail, I have the following connection strings:
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=LOCALCOMPUTER\SQLEXPRESS;Initial Catalog=xxx;Persist Security Info=True;User ID=yyy;Password=zzz" providerName="System.Data.SqlClient"/>
<add name="MembershipConnection" connectionString="metadata=res://*/App_Code.Membership.Membership.csdl|res://*/App_Code.Membership.Membership.ssdl|res://*/App_Code.Membership.Membership.msl;provider=System.Data.SqlClient;provider connection string="Data Source=LOCALCOMPUTER\SQLEXPRESS;Initial Catalog=xxx;Persist Security Info=True;User ID=yyy;Password=zzz;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient"/>
...
xxx, yyy, zzz of course have the proper values. LOCALCOMPUTER is the FDQN of the local computer, which is not on a domain
The first connection string is for the Microsoft login library, while the second uses entity framework from our code.
When I browse to the site, I can successfully access the login form, and if I try to insert a wrong password i get a message saying so, meaning the application managed to check the database using the first connection string, but when i insert a correct one, i land on an exception as soon as the code tries to create a context.
The underlying provider failed on Open.:
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: TCP Provider, error: 0 - The wait operation timed out.)
In the event viewer it tells me that the user has been authenticated via Authentication Type: Forms , which I assume it means the auth system (the one using ApplicationServices connection string) is working, the stack trace confirms that the error occours when I try to use EF in code, meaning the DB has been used succesfully to check user credentials
note that:
The web app works in other environments
I can connect to the sql server using the credentials via SSMS
I've assigned a local windows account to the app pool that can also access the database, and tried changing to Integrated Security=SSPI
Both .Net 3.5 and .Net 4.8 are installed
The database is on the local machine and has been restored from a dump of the other one, its users have been mapped, and to rule out issues i gave it ample authorisations with dbowner datawriter and datareader
I've been trying to fix this since a couple days checking similar issues on SO with no avail and I don't really know how to proceed, is there something I can do to troubleshoot the issue?
Apologies, I've found out the answer, and it's specific to the code base. Apparently the connection string was being ignored (despite being perfectly usable) in favour of data saved in a table.
Had to contact the previous developer to find out, guess it's a good example of how important is to document your code
I'll close the thread, thanks for all who tried to help
I have a long running application that uses NHibernate.ISessionFactory to connect to an Oracle database.
Occasionally the database goes offline (e.g. for weekend maintenance), but even once the database is back online, subsequent queries fail with the following exception (inner exceptions also shown):
NHibernate.Exceptions.GenericADOException: could not execute query
[ select .....]
>> Oracle.ManagedDataAccess.Client.OracleException: ORA-03135: Connection lost contact
>> OracleInternal.Network.NetworkException: ORA-03135: Connection lost contact
>> System.Net.Sockets.SocketException: An established connection
was aborted by the software in your host machine
Restarting the application restores the functionality, but I would like the application to be able to automatically cope without a restart, by "resetting" the connection.
I have tried the following with my ISessionFactory when I hit this exception:
sf.EvictQueries();
sf.Close();
sf = null;
sf = <create new session factory>
but see the same exception after recreating the ISessionFactory. I assume this is because NHibernate is caching the underlying broken connection in some kind of connection pool?
How can I persuade NHibernate to create a genuinely new connection (or even just reset all state completely), and hence allow my application to fix the connection issue itself without an application restart?
EDIT:
Following A_J's answer, note that I am already calling using (var session = _sessionFactory.OpenSession()) for each database request.
I suspect you are opening ISession (call to ISessionFactory.OpenSession()) at startup and closing it at application end. This is wrong approach for any long running application.
You should manage connection at lower level of time. In web application, this is generally handled per request. In your case, you should find what that should be. If yours is windows service that does some activity after specified time then Timer_Tick event is good place.
I cannot suggest what that location could be in your application; you need to find out on your own.
Edit 1
Looking at your edit and comment, I do not think this has anything to do with NHibernate. May be that the connection pool is returning a disconnected/stale connection to NHibernate.
Refer this and this accepted answer.
Good afternoon.
I'm having troubles getting connected to a Postgres database.
The app I'm working on has to run on .NET 4. I'm using Npgsql, and because I'm limited to .NET 4, I'm using Npgsql version 2.2.7 (I believe 3+ requires .NET 4.5).
The application will be running on the same machine as Postgres is. The database is installed and set up by a third party, and for that reason I'm unable to change the pg_hba.conf file.
My first stab at a connection string looked like this:
Server=localhost;Database=xyz;Integrated Security=true;
But I got this error:
FATAL: 28000: no pg_hba.conf entry for host "::1", user "SYSTEM", database "xyz", SSL off
Researched that error, and tried numerous other variations of the connection string to fix this, including:
Server=127.0.0.1;Database=xyz;Integrated Security=true;
Server=-h 127.0.0.1;Database=xyz;Integrated Security=true;
Server=127.0.0.1/32;Database=xyz;Integrated Security=true;
Server=::1;Database=xyz;Integrated Security=true;
Server=::1/128;Database=xyz;Integrated Security=true;
But nothing works. I either get the
FATAL: 28000 ...
error, or a simple
Failed to establish a connection to ...
The pg_hba.conf file looks like this:
host all postgres 127.0.0.1/32 trust
host all xyz 127.0.0.1/32 trust
host all xyz ::1/128 trust
host all postgres ::1/128 trust
This is all running on a Windows 7 machine, and IPv6 is turned off on the network connection.
It's probably something simple, but what can I do? I can't change the pg_hba.conf file, so how can I tweak my connection string to work?
Try this:
"Server=[your server];Port=[your port];Database=[your database];User ID=[your user];Password=[your password];"
For example:
"Server=localhost;Port=5432;Database=BookStore;User ID=operator;Password=1234;"
at the beginning of your pg_hba.conf file add (the order of entries is important!):
# Type database users auth.method
local xyz all sspi
If you don't want user any password to connections.
(For more info check:
https://www.postgresql.org/docs/9.1/static/auth-methods.html#SSPI-AUTH
https://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html
(auth-method -> sspi))
Secound option is add to your ConnectionString as #Cecilia Fernández says.
But then you need to add to your pg_hba.conf file:
# Type database users auth.method
local xyz all md5
Using C# and Oracle Data Provider for .NET (ODP) I made a long query to the database, then I end the connection on the server side using TOAD. After that, the subsequent calls to the database, even creating a new OracleConnection object, throw the following error:
ORA-01012: not logged on
Process ID: xxx
Session ID: yyy Serial number: zzz
Where Process ID and Session ID are the identifiers I used to end the connection.
It seems like when I end the connection to the Oracle database on the server side, the broken connection is returned to the connection pool. And when the C# client code (using ODP) opens a new connection, the broken connection that was returned to the connection pool may be retrieved.
Any ideas on how to fix this behaviour?
BTW I'm using Oracle client 10
I solved my problem by setting to true the "Validate Connection" property in the connection string.
you can read more here
As a warning I quote the Oracle docs.
The Validate Connection attribute validates connections coming out of
the pool. This attribute should only be used when absolutely necessary
because it causes a server round-trip to the database to validate each
connection right before it is provided to the application. If invalid
connections are uncommon, developers can create their own event
handler to retrieve a new connection, rather than using Validate
Connection. This generally provides better performance.
I can't simply connect to my database because of this error
Login failed for user 'sa'
Consider these lines of code:
SqlConnection conn = new SqlConnection("Data Source=arohbi;Initial Catalog=SPADA_FIS;Persist Security Info=True;User ID=sa;Password=p#ssword");
conn.Open();
After the execution of conn.Open() I got this weird error message
Login failed for user 'sa'.
Last time I used this setup and connection string and it work perfectly but one day when I try to connect this message is the only response. Still I manage to connect using management studio. The connection from the serverdatabase to my local machine work perfectly. Anyone guys knows the answer.
Things get worst this time. Take a look at these images:
I used same connection string on both sqlconnection but i was confuse why the other one failed?
Connection string used on both:
Data Source=arohbi;Initial Catalog=SPADA_FIS;Persist Security Info=True;User ID=espada;Password=p#ssword
There are a three primary reasons that I can think of off the top of my head that would cause this:
1) The sa user's password has expired or is different than what you have specified.
2) The sa user has been disabled, either by being denied permission to connect to the database engine or having the login disabled.
3) Your instance of SQL server is not configured for SQL authentication.
Whenever you're trying to troubleshoot a problem like this, boil it down to the simplest reproducible case. Right now, you've got a custom client trying to connect and are interpreting exceptions. Try connecting with a stock client (i.e. Management Studio) and see what happens.
That said, other answers here are spot on. Based on the error message that you're getting, either the sa login has been disabled or the password that you're using for it is incorrect. Contact the administrator of the server to find out how you can connect.