首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Windows Powershell执行SQL脚本

使用Windows Powershell执行SQL脚本
EN

Stack Overflow用户
提问于 2013-01-14 18:41:23
回答 1查看 2.4K关注 0票数 0

我有一个"SQL"脚本,需要通过微软的Powershell运行,以便创建一个数据库。脚本中已经有drop和create函数,因此不需要在命令行末尾添加数据库名称。在尝试执行命令行时,我得到一个错误消息:

代码语言:javascript
复制
"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命令,并且我已经按照此链接How to execute .sql file using powershell?中的步骤进行了操作。有没有可能出现此错误的变通方法。SQLSERVER实例已配置为LocalSystem,而不是网络实例

EN

回答 1

Stack Overflow用户

发布于 2013-01-15 19:52:24

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

代码语言:javascript
复制
   /****** 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. 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14316887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档