SqlLocalDB 公用程式SqlLocalDB Utility

使用SqlLocalDB公用程式來建立的執行個體MicrosoftMicrosoft SQL Server 2014 ExpressSQL Server 2014 Express LocalDBUse the SqlLocalDB utility to create an instance of MicrosoftMicrosoftSQL Server 2014 ExpressSQL Server 2014 ExpressLocalDB. SqlLocalDB公用程式 (SqlLocalDB.exe) 是簡單的命令列工具,可以讓使用者與開發人員建立和管理的執行個體SQL Server ExpressSQL Server Express LocalDBThe SqlLocalDB utility (SqlLocalDB.exe) is a simple command line tool to enable users and developers to create and manage an instance of SQL Server ExpressSQL Server ExpressLocalDB. 如需有關如何使用資訊LocalDB,請參閱SQL Server 2014 Express LocaldFor information about how to use LocalDB, see SQL Server 2014 Express LocalDB.

語法Syntax

SqlLocalDB.exe   
{  
      [ create   | c ] <instance-name><instance-version> [-s ]  
    | [ delete   | d ] <instance-name>  
    | [ start    | s ] <instance-name>  
    | [ stop     | p ] <instance-name>  [ -i ] [ -k ]  
    | [ share    | h ] ["<user_SID>" | "<user_account>" ] "<private-name>""<shared-name>"  
    | [ unshare  | u ] "<shared-name>"  
    | [ info     | i ] <instance-name>  
    | [ versions | v ]  
    | [ trace    | t ] [ on | off ]  
    | [ help     | -? ]  
}  

引數Arguments

[ create | c ] <執行個體名稱> <執行個體版本> [-s ][ create | c ] <instance-name> <instance-version> [-s ]
建立 SQL Server ExpressSQL Server Express LocalDB 的新執行個體。Creates a new of instance of SQL Server ExpressSQL Server ExpressLocalDB. SqlLocalDB 使用新版SQL Server ExpressSQL Server Express所指定的二進位檔*<執行個體版本 >* 引數。SqlLocalDB uses the version of SQL Server ExpressSQL Server Express binaries specified by <instance-version> argument. 使用至少一個十進位數的數字格式指定版本號碼。The version number is specified in numeric format with at least one decimal. 次要版本號碼 (Service Pack) 為選擇性。The minor version numbers (service packs) are optional. 例如下列兩個版本號碼都可接受:11.0 或 11.0.1186。For example the following two version numbers are both acceptable: 11.0, or 11.0.1186. 電腦上必須安裝指定的版本。The specified version must be installed on the computer. 如果未指定,版本號碼會預設新版SqlLocalDB公用程式。If not specified, the version number defaults to the version of the SqlLocalDB utility. 加入 -s 會啟動新的 LocalDB 執行個體。Adding -s starts the new instance of LocalDB.

[ share | h ][ share | h ]
使用指定的共用名稱來共用指定的 LocalDB 私用執行個體。Shares the specified private instance of LocalDB using the specified shared name. 如果省略使用者 SID 或帳戶名稱,會預設為目前的使用者。If the user SID or account name is omitted, it defaults to the current user.

[ unshared | u ][ unshared | u ]
停止共用指定的 LocalDB共用執行個體。Stops the sharing of the specified shared instance of LocalDB.

[ delete | d ] <執行個體名稱>[ delete | d ] <instance-name>
刪除指定的 SQL Server ExpressSQL Server Express LocalDB 執行個體。Deletes the specified instance of SQL Server ExpressSQL Server ExpressLocalDB.

[ start | s ] "<執行個體名稱>"[ start | s ] "<instance-name>"
啟動指定的 SQL Server ExpressSQL Server Express LocalDB 執行個體。Starts the specified instance of SQL Server ExpressSQL Server ExpressLocalDB. 當成功的陳述式傳回 LocalDB的具名管道位址時。When successful the statement returns the named pipe address of the LocalDB.

[ stop | p ] <instance-name> [-i ] [-k ][ stop | p ] <instance-name> [-i ] [-k ]
停止指定的 SQL Server ExpressSQL Server Express LocalDB 執行個體。Stops the specified instance of SQL Server ExpressSQL Server ExpressLocalDB. 新增 -i要求關閉此執行個體,與NOWAIT選項。Adding -i requests the instance shutdown with the NOWAIT option. 加入 -k 會在未經連絡的情況下終止執行個體處理序。Adding -k kills the instance process without contacting it.

[ info | i ] [ <執行個體名稱> ][ info | i ] [ <instance-name> ]
列出目前使用者擁有的所有 SQL Server ExpressSQL Server Express LocalDB 執行個體。Lists all instance of SQL Server ExpressSQL Server ExpressLocalDB owned by the current user.

<執行個體名稱> 會傳回名稱、版本、狀態 (執行中或已停止)、指定之 SQL Server ExpressSQL Server ExpressLocalDB 執行個體的上次啟動時間,以及 LocalDB 的本機管道名稱。<instance-name> returns the name, version, state (Running or Stopped), last start time for the specified instance of SQL Server ExpressSQL Server ExpressLocalDB, and the local pipe name of the LocalDB.

[ trace | t ] on | off[ trace | t ] on | off
在追蹤可追蹤SqlLocalDBAPI 呼叫目前的使用者。trace on enables tracing for the SqlLocalDB API calls for the current user. trace off 停用追蹤。trace off disables tracing.

-?-?
傳回簡短描述每個SqlLocalDB選項。Returns brief descriptions of each SqlLocalDB option.

備註Remarks

<執行個體名稱> 引數必須遵循 [SQL Server]SQL Server 識別碼的規則,或者必須以雙引號括住。The instance name argument must follow the rules for [SQL Server]SQL Server identifiers or it must be enclosed in double quotes.

不使用任何引數執行 SqlLocalDB 會傳回說明文字。Executing SqlLocalDB without arguments returns the help text.

啟動以外的作業只能在屬於目前登入之使用者的執行個體上執行。Operations other than start can only be performed on an instance belonging to currently logged in user.

範例Examples

A.A. 建立 LocalDB 的執行個體Creating an Instance of LocalDB

下列範例會使用 SQL Server ExpressSQL Server Express二進位檔建立名為DEPARTMENT LocalDB SQL Server 2014SQL Server 2014 執行個體,並啟動此執行個體。The following example creates an instance of SQL Server ExpressSQL Server ExpressLocalDB named DEPARTMENT using the SQL Server 2014SQL Server 2014 binaries and starts the instance.

SqlLocalDB.exe create "DEPARTMENT" 12.0 -s  

B.B. 使用 LocalDB 的共用執行個體Working with a Shared Instance of LocalDB

使用管理員權限開啟命令提示字元。Open a command prompt using Administrator privileges.

SqlLocalDB.exe create "DeptLocalDB"  
SqlLocalDB.exe share "DeptLocalDB" "DeptSharedLocalDB"  
SqlLocalDB.exe start "DeptLocalDB"  
SqlLocalDB.exe info "DeptLocalDB"  
REM The previous statement outputs the Instance pipe name for the next step  
sqlcmd -S np:\\.\pipe\LOCALDB#<use your pipe name>\tsql\query  
CREATE LOGIN NewLogin WITH PASSWORD = 'Passw0rd!!@52';   
GO  
CREATE USER NewLogin;  
GO  
EXIT  

使用 登入執行以下程式碼以連接到 LocalDB NewLogin 的共用執行個體。Execute the following code to connect to the shared instance of LocalDB using the NewLogin login.

sqlcmd -S (localdb)\.\DeptSharedLocalDB -U NewLogin -P Passw0rd!!@52  

另請參閱See Also

SQL Server 2014 Express LocalDBSQL Server 2014 Express LocalDB