Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert dynamic data in SQL Server database 1

Status
Not open for further replies.

blombardi

MIS
May 21, 2003
17
US
I am trying to insert MailboxDisplayName and LastLogonTime from my Exchange server into a SQL database. The script executes without errors, but the data is not being inserted. Can someone please tell me what I am doing wrong? Thanks


On Error Resume Next

strComputer = "EXCHANGE"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & _
"\ROOT\MicrosoftExchangeV2")

Set colItems = objWMIService.ExecQuery _
("Select * from Exchange_Mailbox")

strComputerSQL = "SQLSERVER"

Set objConnection = CreateObject("ADODB.Connection")

objConnection.Open _
"Provider=SQLOLEDB;Data Source=" & strComputerSQL & ";" & _
"Trusted_Connection=Yes;Initial Catalog=MailboxUsage"

For Each objItem in colItems
sql = "INSERT INTO TestTable (MailboxName, LastLogonTime) VALUES (MailboxDisplayName, LastLogonTime)"
objConnection.Execute(sql)
Next
 
Perhaps this ?
Code:
For Each objItem in colItems
    sql = "INSERT INTO TestTable (MailboxName, LastLogonTime) VALUES ('" _
    & objItem.MailboxDisplayName & "','" & objItem.LastLogonTime & "')"
    objConnection.Execute(sql)
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top