Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell Test Sql Connection and go-to-backup

$
0
0

I have a fairly substantial powershell script which for its size is simple in that it opens a SQL connection runs a multitude of queries and exports that data.  It works without issue 99% of the time except when the primary server is down.

What I cannot work out and do not know if its possible, and even if it is how it is possible.  Is that I would like to test the connection to the primary ip address

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Data Source=$MISA;Initial Catalog=$DB;
Initial Catalog=$DB;User ID=$userName;Password=$PassWord;"

but should the connection be non available I would want the connection to change the data source variable to

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Data Source=$MISB;Initial Catalog=$DB;
Initial Catalog=$DB;User ID=$userName;Password=$PassWord;"

I have been reading article after article and figure that it is far more simplistic than I am making it but I have admitted defeat temporarily and wondered if anyone else had any experience of solving this issue to save my frustrations growing further?

Your help is most appreciated!

Regards

R


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>