Results 1 to 3 of 3

Thread: OSQL, ISQL remotely?

  1. #1
    Join Date
    Apr 2005
    Posts
    2

    OSQL, ISQL remotely?

    How can you use either OSQL or ISQL from the command line from another server to the machine that the DB is on? I have tried mapping drives to the SQL Server install. There is no sql server agent or enterprise manager client on the machine I am trying to do this from.

    If the drive is mapped to \\<db server machine>\Program Files\MS Sql Server, shouldn't the remote machine be able to run command line utilities as if it were on the remote machine at that directory?

    The error I get is:

    [Shared Memory]SQL Server does not exist or access denied.
    [Shared Memory]ConnectionOpen (Connect()).

    If I can't do it this way, using these utilities, does anybody have a sample script that makes a connection to a SQL Server db and executes a stored procedure with at least one arg?

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    you need SQL Client installed on a machine to run OSQL.exe

    you can use a vbscript to just execute a procedure

    Usage:
    exec1 servername database login password procname parameter1

    Code:


    'on error resume next
    '************************************************* ******************************************
    ' * Objective: To Execute a Procedure
    ' * Created by: MAK
    ' * Date: Apr 15, 2004
    ' *
    '************************************************* ******************************************

    'Check # of arguments
    Set objArgs = WScript.Arguments
    If objArgs.Count < 5 then
    wscript.echo "Syntax: CSCRIPT GenDependScript.vbs Login Password objectlistFile CM# DestinationFolder " & chr(10) & chr(10) & chr(10) & "Usage Example: CSCRIPT GenDependScript.vbs cm cm c:\sqlservercm\objectlist.txt 50880 c:\sqlservercm\files\ "
    wscript.quit
    end if

    ' Assign Arguments to variables
    Server=objArgs(0)
    Database=objArgs(1)
    Login=objArgs(2)
    password=objArgs(3)
    proc=objArgs(4)
    param=objArgs(5)


    'ADODB connection
    Dim AdCn
    Dim AdRec
    Dim i, SQL

    Set AdCn = CreateObject("ADODB.Connection")
    Set AdRec = CreateObject("ADODB.Recordset")

    AdCn.CommandTimeout = 320

    connstring = "Provider=SQLOLEDB.1;Data Source=" & Server & ";Initial Catalog=" & database & ";user id = '" & Login & "';password='" & password & "' "
    'Stream1.WriteLine connstring
    AdCn.Open =connstring
    SQL = "exec " & proc & "'"& param & "'"

    AdRec.Open SQL, AdCn,1,1

    if AdRec.status = 0 then
    msgbox "Execute successfully"
    end if

  3. #3
    Join Date
    Apr 2005
    Posts
    2
    Actually, I forgot to put the -S for the server. It works with that. I was using hostname, but that flag doesn't seem to like our network configuration.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •