I have recently changed a nested folder of a Virtual Directory to an Application within IIS 10.
All database entries worked flawlessly before this change.
Once I changed the nested folder of the Virtual Directory to an Application.
I get
ExecuteReader requires an open and available Connection.
The connections current state is closed.
The connection, however. It is not closed; It is opened for all readers to use.
This is my code for this area.
The database string is within a database.config file.
<add name ="Local" connectionString="Data Source=studio\2016;Database=DBName;User ID=UN;Password=PW;MultipleActiveResultSets=True"/>
con = New SqlConnection(ConfigurationManager.ConnectionStrings("Local").ConnectionString)
con.Open()
Dim chArt As New SqlCommand("select ID, FName from Col1 where ID=@ID", con)
chArt.Parameters.Add(New SqlParameter("@ID", strID))
Dim rschArt As SqlDataReader
rschArt = chArt.ExecuteReader(Data.CommandBehavior.CloseConnection) ' Error line
If rschArt.Read() Then
' other database goodies here.
end if
cn.close()
The connection is closed at the bottom of the file.
There are a lot of different things going on inside of this aspx.vb file
And they all use this connection.
As stated above, all worked flawlessly until I changed the nested folder of the
Virtual Directory -to- an Application within IIS 10.
UPDATE!!!!!!
I did a test on my LIVE Web Server, on the Admin site (So no one will notice the issue by myself)
I set up everything identical as I have on my testing system.
But this time, there is NO Virtual Directory.
Website
Created Virtual Directory => Converted to Application.
Set all permissions for the site's application pool
(Make owner, the domain.local\webserver01)
The same issue happens. So, it does not matter which environment it is. It seems once it is converted to an Application, it messes with the reader object.
Any suggestions on this would be great.
Thanks, EE
So, this was the issue.
The connection con.Open()
It had also to be placed at the top of the ExecuteReader, making the source have 2-instances of the con.open() of which it never needed it before.
And everything went to work.
I am not sure why this stopped working? As I removed the application, and it stayed with the error. Testing on the live server is what threw me off.
Either way, it is working now. For some reason, that one "ExecuteReader."
It needed to have its very own con.open() to work again.