0
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=mydb;Data Source=myserver" 
Set dbconn = CreateObject("ADODB.Connection")
dbconn.Open ConnectionString

DIM cmd
SET cmd = server.CreateObject("ADODB.Command")
SET cmd.ActiveConnection = Connection

cmd.CommandText = "xp_sendmail"
cmd.CommandType = 4 

cmd.Parameters("@Recipients") = "me@me.com" 
cmd.Parameters("@Subject") = "Test" 
cmd.Parameters("@message") = "Test" 

cmd.Execute

My script gives me an error:

Object required: 'server'

Any help will be appreciated. Thanks!

Racil Hilan
  • 22,887
  • 12
  • 43
  • 49
John F
  • 142
  • 11
  • Try removing "server." since you are running the script via WScript/CScript. – Dan Guzman Jul 26 '16 at 02:10
  • Hi, It gave an error: Object Required: ActiveConnection – John F Jul 26 '16 at 02:16
  • Perhaps you intend `dbconn` instead of `Connection`. – Dan Guzman Jul 26 '16 at 02:28
  • Hi, you're correct but it still gives me an error in this line cmd.Parameters("@Recipients") = "me@me.com" item cannot be found in the collection corresponding to the requested name or ordinal – John F Jul 26 '16 at 03:57
  • 1
    I addition to the parameter documentation Ekkehard.Horner provided, I suggest you send the mail directly from your script instead of using a database call. The deprecated `xp_sendmail` has been removed in modern SQL Server versions in favor of `sp_send_dbmail`. See http://stackoverflow.com/questions/7041938/vbscript-to-send-email-without-running-outlook for an example. – Dan Guzman Jul 26 '16 at 11:25

1 Answers1

0

Look here to learn why and how to .Append parameters.

Ekkehard.Horner
  • 37,203
  • 2
  • 36
  • 83
  • Hi @Ekkehard , I've read the documentation but when I used this cmd.parameters.Append cmd.CreateParameter("Recipients", adVarChar, adParamInput, 50, "me@me.com") It gave me error 800A0BB9 arguments are of the wrong type..... – John F Jul 31 '16 at 05:45
  • Did you define the ad* constants? – Ekkehard.Horner Jul 31 '16 at 13:29