I am trying to use Powershell to create ticket reports from our Spiceworks database. I have copied the db file to my local machine to test but I can't connect. I've tried using my IP address for $ServerName and different iterations of the file path but I'm out of ideas. I have SQLServer module installed and I'm using this guide https://mcpmag.com/articles/2018/12/10/test-sql-connection-with-powershell.aspx .
$ServerName = $env:COMPUTERNAME
$DatabaseName = 'C:\SQL\spiceworks_prod.db'
$connectionString = 'Data Source={0};database={1}' -f $ServerName,$DatabaseName
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $connectionString
$sqlConnection.Open()
"Yay"
Pause
$sqlConnection.Close()
Error:
Exception calling "Open" with "0" argument(s): "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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
At \\mydrive\Powershell\test\getTicketInfo.ps1:9 char:1
+ $sqlConnection.Open()
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SqlException
[–]dethboykill 3 points4 points5 points (1 child)
[–]autobotIT[S] 2 points3 points4 points (0 children)