Answered login failure using osql scripts

  • Thursday, January 10, 2013 12:52 PM
     
     

    Hi everyone,

    I'm using SQL Server 2005 Enterprise Edition. Previously I wanted to remotely connect to, say,  Server B from Server A. The firewall has been opened and I can access the database on Server B remotely from Server A using SQL Mgmt Studio. However, if I run a script using OSQL like following:

    OSQL -E -q "select * from Invoice" -S Visibility -d VisibilityTest

    Then I get a login error: Login failed for user 'domain_name\login_name'. Cannot open database "VisibilityTest" requested by the login. The login failed.

    Why I succeeded using SSMS but failed with OSQL? Could you please give some advice? Thank you very much.

    regards,

    Oliver


     

All Replies

  • Thursday, January 10, 2013 2:01 PM
     
     

    Share the complete error message details from SQL Server Visibility  for login failure.


    Regards,
    Rohit Garg
    (My Blog)
    This posting is provided with no warranties and confers no rights.
    Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread.

  • Thursday, January 10, 2013 2:52 PM
    Moderator
     
     Answered Has Code

    Hello,

    If your SQL Server instance is not on the same computer than the one on which you are using OSQL, you must provide the name of the computer on which the Visibility instance is installed for example SqlServerInstanceComputerName\Visibility

    Moreover, your message seems clear : "Login failed for user 'domain_name\login_name'".For me , the Windows login you are using is not known at the level of the VisibilityTest database ( this login is not authorized to connect to the database )

    Your question is not related to SQL Server Data Access.Moreover, i found

    "This feature will be removed in a future version of SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use the feature. Use sqlcmd instead. For more information, see sqlcmd Utility"

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\user>osql -L
    
    Servers:
        (local)
        AD-PC
        AD-PC\SQLEXPRESS1
        USER-PC
        USER-PC\SQLEXPRESS
    
    C:\Users\user>osql -E -S USER-PC\SQLEXPRESS -d AdventureWorksLT2012 -q "select *  from dbo.BuildVersion"
    
     SystemInformationID Database Version          VersionDate
            ModifiedDate
     ------------------- ------------------------- -----------------------
            -----------------------
                       1 11.0.2100.60              2012-03-15 00:00:00.000
            2012-03-15 00:00:00.000
    
    (1 row affected)
    1> e
    2> exit
    
    

    I have done tests with suppress of USER-PC ( the name of the computer on which the SQL Server SQLEXPRESS instance is installed, it is failing

    Don't hesitate to poste for more help or explanations

    Have a nice day

    PS: I hope that you will excusse my awkward english


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.