Blir så förbryllad! >> cmdFill1.Connection.Dispose()The connectionstring property has not been initialized
CONN= Finns deklarerad public och fungerar.
Fill1 resp Fill2 fungerar var för sig.
Anropar dem i följd och får felmeddelande: The connectionstring property has not been initialized.
Sätter jag ihop dem till en rutin får jag samma fel.
Men de fungerar var för sig?!?
Har googlat men det mesta jag hittat pekar på hur det ser ut i webconfig och där är det ok.
Kanske är en smal sak för någon som kan detta på rak arm?
Sub Fill1()
Dim sqlFill1 As String = "SELECT * FROM tbl1"
Dim cmdFill1 As SqlCommand = New SqlCommand(sqlFill1, CONN)
Try
cmdFill1.Connection.Open()
dg1.DataSource = cmdFill1.ExecuteReader()
dg1.DataBind()
cmdFill1.Connection.Close()
cmdFill1.Connection.Dispose()
Catch ex As Exception
lblStatus.Text = ex.Message
End Try
End Sub
Sub Fill2()
Dim sqlFill2 As String = "SELECT * FROM tbl2"
Dim cmdFill2 As SqlCommand = New SqlCommand(sqlFill2, CONN)
Try
cmdFill2.Connection.Open()
dg2.DataSource = cmdFill2.ExecuteReader()
dg2.DataBind()
cmdFill2.Connection.Close()
cmdFill2.Connection.Dispose()
Catch ex As Exception
lblStatus.Text = ex.Message
End Try
End Sub
<b>EDIT:</b> Hittade en lösning här: http://www.vbforums.com/showthread.php?t=404003 citerar:
<citat>You've created the connection outside the method but you're disposing it inside.
That means that once you've executed that method once the connection object has been destroyed.
There's no need to be destroying those objects as it's probably more resource-intensive to keep
creating and destroying them all than it is to just create them once and only destroy them when you
close the form. If you really do want to destroy the objects at the end of the method then you'd have
to be creating them at the start, so that each time you execute the method they will be recreated.
</citat>
Sv: The connectionstring property has not been initialized
du ska inte köra dispose själv , det gör gc'n
Och använd using (minns inte vad det heter i vb) så slipper du ens tänka tanken