When I try to insert a record, I get this error : The underlying provider failed on Open. This error occurs only with IIS and not with VWD 2008\'s webserver. In the EventViewer
In my case, I was using Sql CE, and my connection string was set up with an absolute path instead inf the |DataDirectory| variable. Changed this and it began working on the server.
Obviously, it worked fine on the development machine.
Add the below attribute in the Connection string which you have given.
<add
name="ASPNETDBEntities"
connectionString="metadata=res://*/Models.FriendList.csdl|
res://*Models.FriendList.ssdl|res://*/Models.FriendList.msl;
provider=System.Data.SqlClient;provider connection string="
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;
Integrated Security=True;Connect Timeout=30;
User Instance=True;
MultipleActiveResultSets=True""
ProviderName="System.Data.EntityClient"
User Instance="False"/>
Maybe it's too late to answer but i had the same problem.
I added scope timeout (5 minutes). I let an example.
Dim varIntervalo As New TimeSpan(0, 5, 0)
Using varTransaccion As New TransactionScope(TransactionScopeOption.Required, varIntervalo)
For vari As Integer = 2 To varMatrizDatos.GetUpperBound(0)
Dim varWhateverAs New TABLE
varWhatever.ID_TABLE = something
varWhatever.DESC_TABLE = something else
varWhatever.DATE_TABLE = CDate(Now.Date)
varEntidades.AddToTABLESet(varWhatever)
varEntidades.SaveChanges()
Next
varTransaccion.Complete()
End Using
Maybe this code could be improve.
Using new instance of DB Entity on every action should not physically create connection to your SQL server. Entity Framework will use connection pool created for your (process, app domain, connection string) as configured in your connection string to avoid creating new connections.
This issue is very environmental and tweaking parameters (in your conn string) like below should resolve the problem-
Min Pool Size=1;
Max Pool Size=100; // default
Connect Timeout=15; // in seconds
Pooling=true;
You should create a sql account for your web server to access the aspnetdb database. It is currently using integrated authentication (tries to logon with the identity the web server is using to run the application).
The example below uses integrated auth. I would use SQL auth though.
http://msdn.microsoft.com/en-us/library/ff649314.aspx
I was getting the same problem and after doing debugging i saw that i am creating the new instance of DB Entity on every action and making new instance of Db Entity means openning new connection with db.
Below is the code :
Private tmpConnection As New DbModel.DbEntities
so by calling the variable again and again its creating new instance of DbEntites and opening new connection to db.
so i write a small function for this and that solved my problem. Now no more error.
Private tmpConnection As DbModel.DbEntities
Public Function dbCon() As DbModel.DbEntities
If tmpConnection IsNot Nothing Then
If tmpConnection.Connection.State = ConnectionState.Closed Then
Try
tmpConnection.Connection.Open()
Return tmpConnection
Catch ex As Exception
My.Response.Redirect("dberror.aspx")
End Try
Else
Return tmpConnection
End If
Else
tmpConnection = New DbModel.DbEntities
Try
tmpConnection.Connection.Open()
Return tmpConnection
Catch ex As Exception
My.Response.Redirect("dberror.aspx")
End Try
End If
Return Nothing
End Function
and last thing in your connectionstring please add "Connect Timeout=30;"
thats working so perfect for me