mandelbrot
Well-known member
Dear All,
Im having a bit of bother with the following code. A generic SQL exception is returned each time, but I cant for the life of me track down the problem.
The objective of the code is simply to obtain a connection string from a central database so that we only have to add/change connection strings to this central source to affect every system that relies on it.
If anyone can spot what the problem is Id be really greatful. I think Ive just been looking at this too long...
Many thanks,
Paul.
Im having a bit of bother with the following code. A generic SQL exception is returned each time, but I cant for the life of me track down the problem.
Code:
Private Function GetConnectionString(ByVal paramServer As String, ByVal paramDatabase As String) As String
Define the connection and command to connect to the database name server...
Dim localConn As New System.Data.SqlClient.SqlConnection("integrated security=SSPI;data source=""stm-sysdev""; " & _
"persist security info=False;initial catalog=dbreg; ")
Dim localComm As New System.Data.SqlClient.SqlCommand
Open the connection and set the properties of the connection...
localConn.Open()
localComm.Connection = localConn
localComm.CommandText = "select CONNECTSTRING from dbDef where SERVER=@pServer and DBNAME=@pDatabase "
Define our server and database name as parameters...
localComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("pServer", paramServer))
localComm.Parameters.Add(New System.Data.SqlClient.SqlParameter("pDatabase", paramDatabase))
Read the connection string from the database into the local property...
Return localComm.ExecuteScalar().ToString
localComm.Dispose()
localConn.Close()
localConn.Dispose()
End Function
If anyone can spot what the problem is Id be really greatful. I think Ive just been looking at this too long...
Many thanks,
Paul.