Unable to Open Connection in VB Code But Rest of Site Connects

jlcruzAME

Member
Joined
Oct 18, 2012
Messages
21
Programming Experience
1-3
So in this site we're building, I have a connection String in the web.config to connect to our SQL Server, and it works, as I can create users and login with them. However, I have one page that needs to grab a value from a tasble based on their username. Here is the code that runs:

Dim dbCrew As String
Dim currentCrew As String
Using connObj As New SqlClient.SqlConnection("server=10.161.0.6;database=Webfair;Persist Security Info=False;User ID=ASPPortalLogin;Password=(password here)")
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

It works great on my system where I developed the site, also the SQL Server I was testing with was installed on my laptop as well. When I try to access the page that runs this code I get an error that says it could not open a connection to the SQL Server (error 40 I think). Now, my connection string in the web.config file is the same as what is up there. I'm fairly inexperienced with ASP.NET, so I feel like there might be a better way to do this or that I am missing something. Can anyone help me out?
 
Okay, so I was working with SQL Server 2008 on my laptop which is where I tested it and it worked. However, the SQL Server they're using on the live site is 2012. The connection string I have in my web.config is the same as what I define there for the SqlConnection. Apparently SQL Server 2012 doesn't like that? Is there a way to use these commands in VB.Net to select something out of the database without trying to open the connection again? I am new to VB.Net and ASP.Net and I was looking for something similar to recordsets in VBA and found this piece of code. Any help is appreciated.
 
Back
Top