How to connect Sqlcmd to the server?

前端 未结 3 1987
面向向阳花
面向向阳花 2020-12-28 13:20

I just installed SQL Server 2008, and I wanted to use the command editor to execute queries.

To do that I opened the command prompt, and I typed

Sql         


        
相关标签:
3条回答
  • 2020-12-28 13:29

    (This one is going to sounds silly) my problem was that I wasn't using capital 'S'

    Eg:

    C:\> SQLCMD -S localhost\sqlexpress
    
    0 讨论(0)
  • 2020-12-28 13:31

    The server you are specifying cannot be found or is not accessible. so either the server is wrong (have you spelt it correctly) or you are not specifying it correctly or it is not accessible from your machine.

    After you've got that right, you will need to specify a username/password or a -E command qualifier for a Trusted Connection. You may also need to specify the database with a -d qualifier.

    You can get help by typing

    Sqlcmd -?
    
    0 讨论(0)
  • 2020-12-28 13:35

    You need to either use the integrated-security approach of using your Windows credentials to connect to SQL Server by specifying -E as an option:

    C:\> SQLCMD -S Serverinstance -E
    

    or then you need to define a user/password set to achieve a SQL Server login:

    C:\> SQLCMD -S Serverinstance -U (login in) -P (password)
    

    All the many SQLCMD parameters are well-documented on MSDN SQL Server Books Online!

    0 讨论(0)
提交回复
热议问题