ClevelandSteve
Programmer
I have ASP.net 2.0 application that needs to perform two tasks on an Oracle 10g database. Occasionally, the second task (cn2 in the code) will fail and return a “The ConnectionString property has not been initialized” error. This code has been through many revisions and I cannot figure out what is causing this. Does anyone have any ideas?
Protected Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim streamData As Stream
Dim sr As StreamReader
Dim stringData As String
Dim cn As OracleConnection = New OracleConnection
Dim cn2 As OracleConnection = New OracleConnection
Dim cmd As New OracleCommand
Dim cmd2 As New OracleCommand
cn.ConnectionString = Session("ConnString")
cn2.ConnectionString = Session("ConnString")
lblMessage.Text = ""
streamData = fileLoad.PostedFile.InputStream
sr = New StreamReader(streamData)
Try
stringData = sr.ReadToEnd
Catch ex As Exception
lblMessage.Text = ex.Message
lblMessage.ForeColor = Drawing.Color.Red
Finally
sr.Close()
streamData.Close()
sr.Dispose()
streamData.Dispose()
End Try
With cmd
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "GET_FILE_ID"
.Connection = cn
End With
Try
cn.Open()
cmd.ExecuteNonQuery()
Catch ex As OracleException
lblMessage.Text = ex.Message
lblMessage.ForeColor = Drawing.Color.Red
Finally
cn.Close()
cmd.Dispose()
cn.Dispose()
End Try
With cmd2
.CommandType = Data.CommandType.Text
.CommandText = "Insert Into files(xx) values(xx)"
.Connection = cn2
End With
Try
cn2.Open()
cmd2.ExecuteNonQuery()
Catch ex As OracleException
lblMessage.Text = ex.Message
lblMessage.ForeColor = Drawing.Color.Red
Finally
cn2.Close()
cmd2.Dispose()
cn2.Dispose()
End Try
If lblMessage.Text = "" Then
lblMessage.Text = "File uploaded."
lblMessage.ForeColor = Drawing.Color.Black
End If
lblMessage.Visible = Try
End Sub
Protected Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim streamData As Stream
Dim sr As StreamReader
Dim stringData As String
Dim cn As OracleConnection = New OracleConnection
Dim cn2 As OracleConnection = New OracleConnection
Dim cmd As New OracleCommand
Dim cmd2 As New OracleCommand
cn.ConnectionString = Session("ConnString")
cn2.ConnectionString = Session("ConnString")
lblMessage.Text = ""
streamData = fileLoad.PostedFile.InputStream
sr = New StreamReader(streamData)
Try
stringData = sr.ReadToEnd
Catch ex As Exception
lblMessage.Text = ex.Message
lblMessage.ForeColor = Drawing.Color.Red
Finally
sr.Close()
streamData.Close()
sr.Dispose()
streamData.Dispose()
End Try
With cmd
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "GET_FILE_ID"
.Connection = cn
End With
Try
cn.Open()
cmd.ExecuteNonQuery()
Catch ex As OracleException
lblMessage.Text = ex.Message
lblMessage.ForeColor = Drawing.Color.Red
Finally
cn.Close()
cmd.Dispose()
cn.Dispose()
End Try
With cmd2
.CommandType = Data.CommandType.Text
.CommandText = "Insert Into files(xx) values(xx)"
.Connection = cn2
End With
Try
cn2.Open()
cmd2.ExecuteNonQuery()
Catch ex As OracleException
lblMessage.Text = ex.Message
lblMessage.ForeColor = Drawing.Color.Red
Finally
cn2.Close()
cmd2.Dispose()
cn2.Dispose()
End Try
If lblMessage.Text = "" Then
lblMessage.Text = "File uploaded."
lblMessage.ForeColor = Drawing.Color.Black
End If
lblMessage.Visible = Try
End Sub