sqlcmd help

  • I'm attempting to use sqlcmd below to execute a script file and I'm getting this error message. The database I'm trying to use is in a named instance called lebhq-actsql\itdev. The BookingsCS database is in the itdev named instance. Help please.

    C:\>sqlcmd -s lebhq-actsql\itdev -i c:\data\resetnextnumber.txt

    Msg 911, Level 16, State 1, Server LEBHQ-ACTSQL, Line 1

    Could not locate entry in sysdatabases for database 'BookingsCS'. No entry found with that name. Make sure that the name is entered correctly.

    Msg 208, Level 16, State 1, Server LEBHQ-ACTSQL, Line 1

    Invalid object name 'dbo.workitem_next_number'.

    My resettextnumber.txt script:

    use BookingsCS

    Go

    Update dbo.workitem_next_number

    Set next_number =

    Convert(char(4),Year(Getdate()))

    + right('0' + Convert(varchar,MONTH(GETDATE())), 2)

    + Convert(char(4),'0000')

    Go

  • Patrick,

    Since it looks like SQLCMD is connecting to the instance I would double-check that database name. Maybe test that from the prompt instead of a script file.

    C:\SQLCMD -s lebhq-actsql\itdev

    1> SELECT @@SERVERNAME

    2> GO

    1> SELECT name FROM sys.databases

    2> GO

    1> USE BookingsCS

    2> GO

  • Thanks Todd,

    sqlcmd is using the default instance and not the named instance I specify (lebhq-actsql\itdev).

    Any suggestions?

    C:\>sqlcmd -s lebhq-actsql\itdev

    1> select @@servername

    2> go

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

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

    LEBHQ-ACTSQL

    (1 rows affected)

    1> select name from sys.databases

    2> go

    name

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

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

    master

    tempdb

    model

    msdb

    ReportServer

    ReportServerTempDB

    (6 rows affected)

    1> use BookingsCS

    2> go

    Msg 911, Level 16, State 1, Server LEBHQ-ACTSQL, Line 1

    Could not locate entry in sysdatabases for database 'BookingsCS'. No entry found

    with that name. Make sure that the name is entered correctly.

  • It looks like the server name parameter (-S) must be in uppercase.

    This worker:

    C:\>sqlcmd -S lebhq-actsql\itdev

    1> select @@servername

    2> go

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

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

    LEBHQ-ACTSQL\ITDEV

    (1 rows affected)

Viewing 4 posts - 1 through 3 (of 3 total)

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