none
Insert SQL table from powershell to SQL 2000 RRS feed

  • Question

  • Hey guys,

               Im far from a Powershell guru and DEFINITELY not a SQL guy. With that being said, I'm trying to write a SQL table(2000) from a powershell script I have written. The script is using the FileSystemWatcher to write any new files that have a .tif file extension to a SQL table.

    Obviously, This is not working. Here's my insert code.

    $conn=New-ObjectSystem.Data.SqlClient.SqlConnection("Data Source=$SQLServerName; Initial Catalog=$SQLDatabase; Integrated Security=TRUE")

         

    $conn.Open()

         

    $insert_stmt="INSERT INTO in_cofa_pvs (in_item_key, in_lot_key, imgfileName, in_cofa_crtdt) VALUES ('$item','$lot','$name','$timestamp')"


         

    $cmd=$conn.CreateCommand()

         

    $cmd.CommandText =$insert_stmt


         

    $cmd.ExecuteNonQuery()

         

    $conn.Close()

    I guess I have two questions. 1 is my code looking correct ? All the variables are defined in code prior. 2 can I even use Powershell to insert tables into SQL 2000 ? and 3 if question 1 is YES and 2 is YES what the heck am I doing wrong here ?

    Is there a way that I can log my SQL attempts to see failure/success ? Obviously the first is going to be the case. But when I have it working I would like to see if either is true.

    Thanks Guys

    Rich


    Rich Thompson

    Monday, June 16, 2014 2:19 AM

Answers

All replies