繁体   English   中英

使用Windows Powershell执行SQL脚本

[英]Executing a SQL script using Windows Powershell

我有一个"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而不是Network实例

我已经弄清楚出了什么问题。 创建数据库时,脚本中有一行出现问题,当我从脚本中删除该行时,它没有问题。 问题出在哪里:

   /****** 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. 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM