J
John Cosmas
I am trying to build an application that requires me to locate/detect the
versions of SQL SERVER. I've successfully enumerated my SQL SERVERS, but I
need to now find out what version of SQL they run. I know there are some
STORED PROCEDURES like SP_HELPFILE that you can run to get information about
your server and database. Specifically, I need to figure out how to connect
to the server and get version information for now using code that resembles
the following.
Dim pobjConnection As System.Data.SqlClient.SqlConnection
pobjConnection = New System.Data.SqlClient.SqlConnection("SERVER=" &
pstrServerName & "DATABASE=master;Trusted_Connection=Yes")
Try
pobjConnection.Open()
Catch pobjException As Exception
MsgBox(pobjException.Source)
Return 0
End Try
Dim pobjCommand As System.Data.SqlClient.SqlCommand
pobjCommand = New System.Data.SqlClient.SqlCommand
Dim pobjDataReader As System.Data.SqlClient.SqlDataReader
With pobjCommand
.Connection = pobjConnection
.CommandType = CommandType.StoredProcedure
.CommandText = "sp_helpfile"
pobjDataReader = .ExecuteReader()
End With
While pobjDataReader.Read
Console.WriteLine(pobjDataReader.Item(0))
End While
pobjConnection.Close()
pobjConnection.Dispose()
pobjConnection = Nothing
As you can see, the test SP I'm using here is going to return the logical
files for the MASTER database.
versions of SQL SERVER. I've successfully enumerated my SQL SERVERS, but I
need to now find out what version of SQL they run. I know there are some
STORED PROCEDURES like SP_HELPFILE that you can run to get information about
your server and database. Specifically, I need to figure out how to connect
to the server and get version information for now using code that resembles
the following.
Dim pobjConnection As System.Data.SqlClient.SqlConnection
pobjConnection = New System.Data.SqlClient.SqlConnection("SERVER=" &
pstrServerName & "DATABASE=master;Trusted_Connection=Yes")
Try
pobjConnection.Open()
Catch pobjException As Exception
MsgBox(pobjException.Source)
Return 0
End Try
Dim pobjCommand As System.Data.SqlClient.SqlCommand
pobjCommand = New System.Data.SqlClient.SqlCommand
Dim pobjDataReader As System.Data.SqlClient.SqlDataReader
With pobjCommand
.Connection = pobjConnection
.CommandType = CommandType.StoredProcedure
.CommandText = "sp_helpfile"
pobjDataReader = .ExecuteReader()
End With
While pobjDataReader.Read
Console.WriteLine(pobjDataReader.Item(0))
End While
pobjConnection.Close()
pobjConnection.Dispose()
pobjConnection = Nothing
As you can see, the test SP I'm using here is going to return the logical
files for the MASTER database.