Connecting via DOS

  • Hi all,

    I am little new to this SQL Server as I have been previously using Open Source Databases. Currently I am faced with a problem, but have been unable to cater to.

    I am trying to build a batch file, that can execute a trigger within the SQL Server Database. The problem is that I have been unable to connect to SQL Server 2000, for e.g. Northwind (Default Database) via DOS Command mode.

    Please note that I have tried to use OSQL however, get an error as Not associated with trusted SQL Server, whereas I am using for connection in Enterprise Manager the Windows Authentication Mode.

    Regards

  • What error are you getting with OSQL?  Can you post the error syntax?  Have you tried the -E switch with OSQL? 

    For example, >OSQL -S <servername> -E -Q "select * from master..sysdatabases"

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Has your Windows account been granted access to the server and database?

    Personally, for running SQL from an external file, I prefer to create a VBScript file instead of DOS.

    If you have the option of upgrading to SQL Server 2005, the replacement for osql is sqlcmd which is a command line based program and may be more intuitive for you to use as you can simply execute ad hoc queries from the command line.


    My blog: SQL Soldier[/url]
    SQL Server Best Practices:
    SQL Server Best Practices
    Twitter: @SQLSoldier
    My book: Pro SQL Server 2008 Mirroring[/url]
    Microsoft Certified Master: SQL Server, Data Platform MVP
    Database Engineer at BlueMountain Capital Management[/url]

  • The error that comes from while connecting is as follows:

    Login failed for user 'admin'. Reason: Not associated with a trusted SQL Server connection

    ------------

    Robert Davis: Well I cannot switch from SQL Server 2000 - 2005 as SQL Server 2000 supports a live database, that is currently running. Hence there is no alternative

    By the way while going through the documentation I have found out that osql is able to connect to a Systems Database, and not with a database like default 'Northwind' that comes with SQL Server 2000, or any other created database.

    Is that correct.

    Thanks for the reply anyways.

  • Can you post the syntax you are using in your connect string for OSQL? 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Osql can connect to any database that the user has been granted access to.


    My blog: SQL Soldier[/url]
    SQL Server Best Practices:
    SQL Server Best Practices
    Twitter: @SQLSoldier
    My book: Pro SQL Server 2008 Mirroring[/url]
    Microsoft Certified Master: SQL Server, Data Platform MVP
    Database Engineer at BlueMountain Capital Management[/url]

  • try this:

    osql -S servername -d databasename -E -Q"select * from orders"

     

    -E param tells OSQL to use the trusted connection (your windows account) to access the database so you don't have to give the -U (user) and -P (password) params. Of course, sql server has to be set to accespt trusted connections, which most probably is.

    Link: OSQL sintax (http://www.di-mgt.com.au/osqlUtility.htm)

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • Probably not relevant in this instance, but worth mentioning:  If the SQL Server is in a different domain than your Windows account, there must be a trust between the SQL Server's domain and your domain defined in the network configuration. If the SQL Server's domain can not access your domain to verify your Windows account, the account won't be trusted even if it is the sa account.


    My blog: SQL Soldier[/url]
    SQL Server Best Practices:
    SQL Server Best Practices
    Twitter: @SQLSoldier
    My book: Pro SQL Server 2008 Mirroring[/url]
    Microsoft Certified Master: SQL Server, Data Platform MVP
    Database Engineer at BlueMountain Capital Management[/url]

  • Thanks you gentlemen for your help - I have finally connected to SQL Server via DOS and you were right the problem was the Domain, everything else was right.

Viewing 9 posts - 1 through 8 (of 8 total)

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