(un?) related question re:sp_droplinkedsrvlogin -
11-04-2003
, 01:52 PM
Hi all,
I'm trying to drive sp_droplinkedsrvlogin, sp_dropserver,
sp_addlinkedsrvlogin and sp_addlinkedserver programmatically (VB6.0,
ADO). I think I've got it working, but it's kinda gross. I'm
wondering if there's a clean up.
My specific question is how should I handle NULL parameters. Currently
I check the string arguments and if they're vbNullString I stick a
NULL in, instead of the value. I've checked the routines in
QueryAnalyzer (sp_helptext) and see the checks for null. As I said
this works, but there's probably a better way. Any ideas? Cheers. DEM
For example - this is what my DropLinkServer() code looks like:
Public Sub DropLinkedSrvLogin(rmtSvrName As String, localUser As
String, strConnect As String)
On Error GoTo ErrorHandler
Dim oCmd As ADODB.command
Dim strSQL As String
oCn.Open strConnect
oCn.BeginTrans
Set oCmd = New ADODB.command
With oCmd
.ActiveConnection = oCn
.CommandText = "sp_droplinkedsrvlogin"
.CommandType = adCmdStoredProc
.CommandTimeout = 15
.Parameters.Append .CreateParameter("returncode", adInteger,
adParamReturnValue)
.Parameters.Append .CreateParameter("@rmtsrvname", adVarWChar,
adParamInput, 128, rmtSvrName)
If Not localUser = vbNullString Then
.Parameters.Append .CreateParameter("@locallogin",
adVarWChar, adParamInput, 128, localUser)
Else
.Parameters.Append .CreateParameter("@locallogin",
adVarWChar, adParamInput, 128, Null)
End If
End With
On Error GoTo ErrorDoesNotExist
oCmd.Execute , , adExecuteNoRecords |