Application/Object reference not set to an instance of an object

A

Andrew

Hello,

I'm getting an error in this code.

''' Begin code
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("ConnString") = "myString"
End Sub

Public Class Main

Inherits System.Web.UI.Page
Dim myConnection As SqlConnection = New
SqlConnection(Application("ConnString")) '<-- "Object reference not set to
an instance of an object"

...

End Class
''' End code

Not sure why I'm getting this error. Any help is very much appreciated.

Andrew
 
A

Andrew

I think I figured this out. I was creating and initializing the variable in
one line of code. C# is fine with this but it seems vb.net didn't care for
it. I moved the init code to the Page_Load() event and it works ok now.

Just in case anyone else runs into that.

Andrew


"Andrew"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top