MS SQL and Powershell Studio
Posted: Thu Mar 26, 2020 1:40 am
Hi all,
i have a Problem using SQL and PowerShell-Studio lates Version 64Bit.
in PowerShell-Studio the Code doesn't work. If i use
PowerShell-ISE the Code works fine.
i have a Problem using SQL and PowerShell-Studio lates Version 64Bit.
in PowerShell-Studio the Code doesn't work. If i use
PowerShell-ISE the Code works fine.
- $sqlCon = New-Object System.Data.SqlClient.SqlConnection
- $sqlCon.ConnectionString = "Data Source=OFWHSQT1\INFRASTRUKTUR; Integrated Security=True; Initial Catalog=Anmeldedatenbank"
- $sqlCon.open()
- $sqlCmd = New-Object System.Data.SqlClient.SqlCommand
- $sqlCmd.Connection = $sqlCon
- $strCmd = "Select * from Usermappings where username = '$env:USERNAME' and MappingType ='P'"
- $sqlCmd.CommandText = $strCmd
- $sqlReader = $sqlCmd.ExecuteReader()
- # +++ Datensätze einlesen
- # F_WriteLogFile ("Folgende Drucker wurden in der Datenbank gefunden!")
- $intLoopcount = 0
- [color=#FF0000]The following part doesn't work. PowerShell jumps straight to SQLReader Close[/color]
- While ($sqlReader.Read())
- {
- [String]$strServer = $sqlReader.Item("PrintServer").ToString().Trim()
- [String]$strShareName = $sqlReader.Item("ShareName").ToString().ToUpper()
- [String]$strPrinterName = $sqlReader.Item("PrinterName").ToString().ToUpper()
- [String]$strPath = "\\" + $strServer + "\" + $strShareName
- [String]$strKey = "\\" + $strServer + "\" + $strPrinterName
- $dicDBprinter.Add($strKey, $strPath)
- [Int]$intLoopcount = $intLoopcount + 1
- #F_WriteLogFile("`t" + $strPrinterName)
- If ($intLoopcount -gt 30)
- {
- #F_WriteLogFile "Möglicher Fehler in DB, Druckeranbindung in Schleife hängengeblieben!!"
- [Bool]$bolLoopdetect = $True
- Exit
- }
- }
- $sqlReader.Close()