0

データベースを作成するために"SQL"Windows で実行する必要があるスクリプトがあります。Powershellスクリプトには既にドロップおよび作成機能が含まれているため、コマンド ラインの最後にデータベース名を追加する必要はありません。コマンドラインを実行しようとすると、次のエラーが表示されます

"Invoke-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to SQL Server
The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)
At line:1 char:14
+ invoke-sqlcmd <<<<  -inputfile "c:\A.sql" -serverinstance "Louis_dev\MSSQLSERVER"
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
    + FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Invoke-Sqlcmd :
At line:1 char:14
+ invoke-sqlcmd <<<<  -inputfile "c:\A.sql" -serverinstance "Louis_dev\MSSQLSERVER"
    + CategoryInfo          : ParserError: (:) [Invoke-Sqlcmd], ParserException
    + FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand"

それがinvokeコマンドであるかどうかわからないので、すでにこのリンクの手順に従っていますPowershellを使用して.sqlファイルを実行する方法? . このエラーの回避策がある可能性はありますか。SQLSERVERインスタンスは、ネットワーク インスタンスに対して構成されLocalSystemていて、ネットワーク インスタンスに対して構成されていません

4

1 に答える 1

0

私は何がうまくいかなかったのかを理解しました。データベースを作成するときに、スクリプトに問題を引き起こしている行がありました。スクリプトからその行を削除すると、問題は発生しませんでした。問題は次の場所で発生しました。

   /****** Object:  Database [dbname]    Script Date: 01/03/2013 06:53:20 ******/
   CREATE DATABASE [Mdbname] -- ON  PRIMARY 
    **--( NAME = N'dbname', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\dbname.mdf' , SIZE = 30417920KB , MAXSIZE =   UNLIMITED, FILEGROWTH = 1024KB )
   -- LOG ON 
   --( NAME = N'dbname_log', FILENAME = N'C:\Program Files\Microsoft SQL  Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\dbname_1.ldf' , SIZE = 28333632KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
 --GO**. Normally  its not the best idea to comment those sections out, but i had no          other choice. Databases were created and tables, stored procs, functions and views were all put into their rightful places. 
于 2013-01-15T11:52:23.780 に答える