Is there an open source equivalent to sqlcmd.exe?

  • If you know powershell you can use a simple powershell script to do that for you, no need for the sqlps.exe.

    You can use this to get you started for the connection part:

    $ConnectionTimeout=5

    $conn=new-object System.Data.SqlClient.SQLConnection

    #$conn.ConnectionString=”Server={0};Database=master;Integrated Security=True;Connect Timeout={1};” -f $instFQD,$ConnectionTimeout

    $conn.ConnectionString=”Server={0};Database=master;Integrated Security=no;User ID=sa;Connect Timeout={1}; Password={2};Pooling=no;” -f $instFQD,$ConnectionTimeout,$saPass

    $conn.Open()

    $SQLQuery = "Select @@version"

    $cmd=new-object system.Data.SqlClient.SqlCommand($SQLQuery,$conn)

    $cmd.CommandTimeout=5

    $dt=New-Object system.Data.DataTable

    $da=New-Object system.Data.SqlClient.SqlDataAdapter($cmd)

    [void]$da.fill($dt)

    #Do something with the output

    $conn.Close();

    $conn.Dispose()

  • Oliiii (5/30/2013)


    If you know powershell you can use a simple powershell script to do that for you, no need for the sqlps.exe.

    You can use this to get you started for the connection part:

    Thanks! I just found the following promising links a few minutes ago too:

    http://www.itbigbang.com/how-to-send-connect-and-query-sql-server-using-powershell/

    http://technet.microsoft.com/en-us/magazine/hh289310.aspx

    And Lowell sent me some code as well.

    I am in the process of checking it out.

Viewing 2 posts - 16 through 16 (of 16 total)

You must be logged in to reply to this topic. Login to reply