vbscript - Trying to use a VB Script in an SSIS package to get the Server name from a connection -


i'm writing ssis package uses vb scripts send several confirmation emails. 1 of confirmation emails needs have name of server 1 of connection managers. have script doing following:

public sub main()      '------------- set vriables     dim htmlmessageto string = _       dts.variables("email_to").value.tostring     dim htmlmessagecc string = _       dts.variables("email_cc").value.tostring     dim htmlmessagefrom string = _       dts.variables("email_from").value.tostring      dim serveraconnectionstring string = _           directcast(dts.connections("servera").acquireconnection(dts.transaction), string)     dim smtpconnectionstring string = _           directcast(dts.connections("mail1").acquireconnection(dts.transaction), string)     dim smtpserverstr string = _       smtpconnectionstring.split(new char() {"="c, ";"c})(1)      dim smtpserver new smtpclient(smtpserverstr)      dim mymail new mailmessage     mymail         .from = new mailaddress(htmlmessagefrom)         .to.add(htmlmessageto)         if len(htmlmessagecc) > 0             .cc.add(htmlmessagecc)         end if         .isbodyhtml = true         .subject = "the process failed server " & serveraconnectionstring          .body = "the process failed server " & serveraconnectionstring      end      smtpserver.send(mymail)      dts.taskresult = scriptresults.success end sub 

where i'm trying server name of servera. , connection manager mail1 smtp server i'm using. working fine other strings particular 1 gives me error. believe can connection string don't know enough vb parse it. i'm hoping there way connection object , view server name property, haven't been able find it.

for ado.net connections:

    dim dbconn system.data.sqlclient.sqlconnection = dts.connections("servera").acquireconnection(dts.transaction)     dim dbserver string = dbconn.datasource     dts.events.fireinformation(-1, "", dbserver, string.empty, -1, false) 

it yields following in log:

 [] information: servername\instancename 

oledb connections bit trickier -- access same thing in vb script, add reference .net assembly microsoft.sqlserver.dtsruntimewrap, use following:

    dim connectionmanager connectionmanager = dts.connections("oledbconnection")     dim cmparam microsoft.sqlserver.dts.runtime.wrapper.idtsconnectionmanagerdatabaseparameters100     cmparam = ctype(connectionmanager.innerobject, wrapper.idtsconnectionmanagerdatabaseparameters100)     dim conn oledb.oledbconnection = ctype(cmparam.getconnectionforschema(), oledb.oledbconnection)     dts.events.fireinformation(-1, "", conn.datasource, string.empty, -1, false) 

tested , verified reference: http://blogs.msdn.com/b/mattm/archive/2008/08/22/accessing-oledb-connection-managers-in-a-script.aspx


Comments