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?
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?