Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Object reference not set to an instance of an object." error

Status
Not open for further replies.

Catadmin

Programmer
Joined
Oct 26, 2001
Messages
3,097
Location
US
Okay, this is probably a stupid question, but I can't find the answer anywhere, so I'm going to ask anyway. I'm new to VB .Net (and visual studio), so please forgive me in advance.

I have the following module in my application:

Code:
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Imports System.Data.SqlClient

Module CreateInitialConnection
    Public ProdServer As New Server()
    Public ProdConn As ServerConnection

    Public Sub CreateMyConnection()

        ProdConn = ProdServer.ConnectionContext
        ProdConn.ServerInstance = "Z0185DBS0310V3, 1433"

    End Sub
End Module

I also have a start up screen form with 2 radio buttons. One button leads to a "Create Database Snapshot" form and the other leads to a "Create Database Backup" form. If I choose one (doesn't matter which), the secondary form pops up and the operation concludes succesfully. I can then close the secondary form with the upper right X and see the startup form again. If I then try to chose the other secondary form, it gives me the "Object reference not set to an instance of an object" error.

In the top of both secondary forms, I'm calling the connection with "CreateMyConnection()". I figure this is where I'm going wrong, because Visual Studio seems to think I'm trying to reset the connection objects, when I'm really not.

How can I call the Connection stuff again so it doesn't matter which form I choose, it'll still maintain the same Server information?

Thanks,


Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
Sorry, I forgot to mention that I'm also getting a "Connection properties cannot be changed after a connection has been established" error.



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
Opps. Nevermind, and thank you to all who read this thread. I finally figured it out.

I just needed to add the CreateMyConnection() call to the initial startup form instead of the individual secondary forms. Commenting it out on the secondary forms and putting it in the startup form resolved that particular problem.

Sorry, I was having a "MONDAY" kind of Monday, if you know what I mean. @=)



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top