Friday, March 30, 2012

Internal connection fatal error.

Hi all,

I don’t know what happened to this function which was working OK for a few month and today it doesn’t work.

In debug mode I kip getting “InvalidOperationaException was unhandled by user code”

On this line:

dtrResults = cmdSelect.ExecuteReader()

Same behaviour on developping PC

I cant find anithing that would create that problem.

 Function GetUserInfo(ByVal myUsr As String, ByVal strRequest As String) As String Dim strConString As String Dim conUsers As SqlConnection Dim cmdSelect As SqlCommand strConString = ConfigurationSettings.AppSettings("conString2") conUsers = New SqlConnection(strConString) Dim dtrResults As SqlDataReader Dim intField As Integer Dim usr As String usr = "select " & strRequest & " user_ID from userlist where ul_user='" usr &= myUsr & "'" conUsers.Open() cmdSelect = New SqlCommand(usr, conUsers) dtrResults = cmdSelect.ExecuteReader() While dtrResults.Read() For intField = 0 To dtrResults.FieldCount - 1 GetUserInfo = dtrResults(intField).ToString() Next End While conUsers.Close() dtrResults.Close() Return GetUserInfo End Function

Any Help will highly appriciated.

Alex.

(1) I recommend using parameterized queries. I doubt if your SQL is building properly. What does your strRequest typically have?

(2) Also some exception handling might help.

No comments:

Post a Comment