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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem executing Sql Statements

Status
Not open for further replies.

Corran007

Programmer
May 20, 2002
530
US
Background. I want to be able to run any non results returning sql statements, mostly create and drop stored procedures on multible servers without having to do it in q analyzer since we have a large amount of servers and it is time consuming to do it that way. Its all the same db, username and password, only the server changes.

so i have a table that lists my servers that i loop through the selected servers. It works great sometimes... For simple regular sql it works good like Inserts, updates it does some stored procedures. I can create simple ones. Seems to have a problem with go. Im pretty sure my code is correct since it does work sometimes. But i want it to be able to work all the time. The error it gives is "An unhandled exception of type 'System.NullReferenceException' occurred in MultiAnalyzer.exe

Additional information: Object reference not set to an instance of an object." It seems to be a general sql problem. Anyone have ideas? Also if anyone has a different way to do it, please feel free to suggest it.

Servername and strtext are passed in text being the sql statement.

Dim con As New SqlConnection("data source=" & Servername & ";initial catalog=Softwise;password="""";persist security i" & _
"nfo=True;user id=sa;packet size=4096")

Dim cmd As New SqlCommand(Trim(strText), con)
Dim intRows As Integer
Try
cmd.Connection.Open()
intRows = cmd.ExecuteNonQuery()
Catch
Dim aE As SqlException
MessageBox.Show(aE.Message.ToString())
End Try
con.Close()

Thanks for any help provided
 
You might need some more debugging on it. It doesn't seem to be the way you create your connection string the problem but more one of the stored procedures that is trying to work with a null field/value.
If one of the server(s) table fields has the Accept Nulls property disabled and all the other db servers have it, you would get that error.

hope this directs you towars the right way. Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top