sql connect jobtracker

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Gordeev Alexaender
Posts: 10
Last visit: Tue Jan 09, 2018 1:50 am

sql connect jobtracker

Post by Gordeev Alexaender »

hi,

$test= {
1
[void][Reflection.Assembly]::Load("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
$sqlConnectionString= 'Data Source=xama;Initial Catalog=adm;Integrated Security=False;User ID=xxx;Password="xxxx"'
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection ($sqlConnectionString)
$sqlConnection|Out-File $dir\test.txt -Append
$sqlConnection.Open()
}


Add-JobTracker -Name 'job' -JobScript $test -UpdateScript {
param ($job)

$results = Receive-Job -Job $Job | Select-Object -Last 1


} -CompletedScript {
Param ($Job)


}

job tracker without working, ok.
But in JobTracker variable is empty.
Any ideas?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: sql connect jobtracker

Post by jvierra »

Jobtracker cannot create a connection. It can return data but the connection will be closed whe the job completes.


You do not need to load System.Data. It comes built into a PowerShell Session.

Test at a prompt like this:
  1. $test = {
  2.     $sqlConnectionString = 'Data Source=xama;Initial Catalog=adm;Integrated Security=False;User ID=xxx;Password="xxxx"'
  3.     $sqlConnection = New-Object System.Data.SqlClient.SqlConnection ($sqlConnectionString)
  4.     $sqlConnection.Open()
  5.     $sqlConnection|select *
  6. }
  7.  
  8. Start-Job -ScriptBlock $test | Wait-Job | Receive-Job
User avatar
Gordeev Alexaender
Posts: 10
Last visit: Tue Jan 09, 2018 1:50 am

Re: sql connect jobtracker

Post by Gordeev Alexaender »

$MainForm_Load={
#TODO: Initialize Form Controls here

}



$test = {
$sqlConnectionString = 'Data Source=xxx;Initial Catalog=xxx;Integrated Security=False;User ID=adm;Password=xxx'
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection ($sqlConnectionString)
$sqlConnection.Open()
$sqlConnection | select *
}


$button1_Click={
#TODO: Place custom script here
Start-Job -ScriptBlock $test | Wait-Job | Receive-Job
}


Interesting. If I run the script then everything is OK. If in windows form, then the result is zero. What am I doing wrong?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: sql connect jobtracker

Post by jvierra »

I asked you to run it at a prompt. Not is a form. You cannot see any output in a form. Forms do not work like you think.

Open PowerShell and paste my code in and look at the output.
User avatar
Gordeev Alexaender
Posts: 10
Last visit: Tue Jan 09, 2018 1:50 am

Re: sql connect jobtracker

Post by Gordeev Alexaender »

I am very sorry.
:roll: :roll: :roll: :roll: I wrote debug itself, and made variable for the script block. Everything works perfectly. I feel very sorry, sorry again ((

PS How do I know the form. That is why in the code did export to txt. Something like a log. :roll:
This topic is 7 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked