Below is a piece of code I'm using right now to grab a value from a table on the SQL Server. The site is on the Web Server.
EDIT: Apparently it put a space between connectionstr and gs, it is correct in the actual code.
I can ping the SQL Server. I can log in to the site with one of the users I've created (indicating the site and SQL Server are communicating). What I can't do is run this code when I open a second page. It errors out on the line connObj.open() and hits me with this error:
Now, both myself and a co-worker have got this site to run correctly on our own laptops (with the SQL Server being on our laptops as well).
Is there something wrong with my code that would cause it to not connect when on a different server than the SQL Server? I know they've opened the ports that need to be opened in order for the Web Server to communicate with the SQL Server.
Any ideas what could be causing the error? All the threads I've found talk about checking that the name is correct or that the SQL Server allows remote connections and what not, and I've already verified all those things. Any help would be greatly appreciated, I'm at the end of my rope here with this error.
Dim dbCrew As String
Dim currentCrew As String
Using connObj As New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
Using cmdObj As New SqlClient.SqlCommand("SELECT CrewID FROM dbo.CrewAssociation WHERE UserID = '" & Context.User.Identity.Name & "'", connObj)
connObj.Open()
Using readerObj As SqlClient.SqlDataReader = cmdObj.ExecuteReader
'This will loop through all returned records
While readerObj.Read
dbCrew = readerObj("CrewID").ToString
currentCrew = dbCrew
End While
End Using
connObj.Close()
End Using
End Using
EDIT: Apparently it put a space between connectionstr and gs, it is correct in the actual code.
I can ping the SQL Server. I can log in to the site with one of the users I've created (indicating the site and SQL Server are communicating). What I can't do is run this code when I open a second page. It errors out on the line connObj.open() and hits me with this 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Now, both myself and a co-worker have got this site to run correctly on our own laptops (with the SQL Server being on our laptops as well).
Is there something wrong with my code that would cause it to not connect when on a different server than the SQL Server? I know they've opened the ports that need to be opened in order for the Web Server to communicate with the SQL Server.
Any ideas what could be causing the error? All the threads I've found talk about checking that the name is correct or that the SQL Server allows remote connections and what not, and I've already verified all those things. Any help would be greatly appreciated, I'm at the end of my rope here with this error.
Last edited: