0

I have a "SQL" script that needs to be run through Windows Powershell in order to create a database. The script already has the drop and create function in so no need to add a database name at the end of the command line. when trying to execute the command line I get an error that says

"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"

not sure if it is the invoke command and I have already followed the steps in this link How to execute .sql file using powershell? . Is there by any chance that there could be a workaround from this error. SQLSERVER instance has been configured to LocalSystem and not to Network instance

8
  • Your sql instance have enabled tcp/ip and named pipes protocols? Commented Jan 14, 2013 at 10:48
  • Where can i check for this? Commented Jan 14, 2013 at 10:55
  • According to this my SQLServer instance is installed as LocalSystem. must i change this to Network Service? Commented Jan 14, 2013 at 11:01
  • check this: msdn.microsoft.com/en-us/library/bb909712(v=vs.90).aspx and this social.msdn.microsoft.com/Forums/en/sqlsecurity/thread/… Commented Jan 14, 2013 at 11:04
  • Are you able to use other tools successfully i.e. SSMS, sqlcmd.exe and even setup a test DSN? Commented Jan 14, 2013 at 16:49

1 Answer 1

0

I have figured out what went wrong. When creating the database there was a line in the script that was giving a problem, when i removed the line from the script it went through with no problems. The Problem came in where:

   /****** 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. 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.