![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Problem on first execution to SQLServer table Hi, I have a script which gathers information from a SQLServer table but it errors on the first execution. On subsequent calls, there is no errors and executes fine. I think this may be due to a process which starts and listens for other calls from SQLServer. Does anyone know how to resolve this? Here is the script: $DB = "server=sqlhost;integrated security=true;database=test" $conn = new-object System.Data.SqlClient.SqlConnection $conn.ConnectionString = $DB $conn.Open() $cmd = new-object System.Data.SqlClient.SqlCommand $cmd.Connection=$conn $cmd.CommandText=" SELECT * from notes" $rdr = $cmd.ExecuteReader() While($rdr.Read()){ write-output "$($rdr['notes_id'])" write-output "$($rdr['notes'])" } $conn.Close() ============================================= Here is the error: [D:\scp]: ./f.ps1 Exception calling "ExecuteReader" with "0" argument(s): "A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)" At D:\scp\f.ps1:13 char:26 + $rdr = $cmd.ExecuteReader( <<<< ) You cannot call a method on a null-valued expression. At D:\scp\f.ps1:15 char:16 + While($rdr.Read( <<<< )){ ============================== Thanks in advance, |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Problem on first execution to SQLServer table It doesn't seem to be your script as you have a $conn.Close() in it. What else do you have running that could have an open connection? -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Frank" wrote: Quote: > Hi, > > I have a script which gathers information from a SQLServer table but it > errors on the first execution. On subsequent calls, there is no errors and > executes fine. I think this may be due to a process which starts and listens > for other calls from SQLServer. Does anyone know how to resolve this? Here > is the script: > > $DB = "server=sqlhost;integrated security=true;database=test" > $conn = new-object System.Data.SqlClient.SqlConnection > $conn.ConnectionString = $DB > $conn.Open() > $cmd = new-object System.Data.SqlClient.SqlCommand > $cmd.Connection=$conn > > $cmd.CommandText=" > SELECT * from notes" > $rdr = $cmd.ExecuteReader() > While($rdr.Read()){ > write-output "$($rdr['notes_id'])" > write-output "$($rdr['notes'])" > } > $conn.Close() > ============================================= > > Here is the error: > > [D:\scp]: ./f.ps1 > Exception calling "ExecuteReader" with "0" argument(s): "A transport-level > error has occurred when sending the request to the server. (provider: TCP > Provider, error: 0 - An existing connection was forcibly closed by the remote > host.)" > At D:\scp\f.ps1:13 char:26 > + $rdr = $cmd.ExecuteReader( <<<< ) > You cannot call a method on a null-valued expression. > At D:\scp\f.ps1:15 char:16 > + While($rdr.Read( <<<< )){ > ============================== > > Thanks in advance, > > |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Problem on first execution to SQLServer table I guess I don't really understand the question. When I first run this script, I get the error below. When I rerun this script, I don't get the error. Before I do the first execution of this script, I do a "sp_who2" in SQLServer and kill all processes that has the DB open. Does that help? Thanks, "RichS" wrote: Quote: > It doesn't seem to be your script as you have a $conn.Close() in it. What > else do you have running that could have an open connection? > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "Frank" wrote: > Quote: > > Hi, > > > > I have a script which gathers information from a SQLServer table but it > > errors on the first execution. On subsequent calls, there is no errors and > > executes fine. I think this may be due to a process which starts and listens > > for other calls from SQLServer. Does anyone know how to resolve this? Here > > is the script: > > > > $DB = "server=sqlhost;integrated security=true;database=test" > > $conn = new-object System.Data.SqlClient.SqlConnection > > $conn.ConnectionString = $DB > > $conn.Open() > > $cmd = new-object System.Data.SqlClient.SqlCommand > > $cmd.Connection=$conn > > > > $cmd.CommandText=" > > SELECT * from notes" > > $rdr = $cmd.ExecuteReader() > > While($rdr.Read()){ > > write-output "$($rdr['notes_id'])" > > write-output "$($rdr['notes'])" > > } > > $conn.Close() > > ============================================= > > > > Here is the error: > > > > [D:\scp]: ./f.ps1 > > Exception calling "ExecuteReader" with "0" argument(s): "A transport-level > > error has occurred when sending the request to the server. (provider: TCP > > Provider, error: 0 - An existing connection was forcibly closed by the remote > > host.)" > > At D:\scp\f.ps1:13 char:26 > > + $rdr = $cmd.ExecuteReader( <<<< ) > > You cannot call a method on a null-valued expression. > > At D:\scp\f.ps1:15 char:16 > > + While($rdr.Read( <<<< )){ > > ============================== > > > > Thanks in advance, > > > > |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Problem on first execution to SQLServer table Do you have SQL management studio or anything open?? I was wondering if there was a connection there that could be causing your problem. The error message you are getting is related to the connection and as you have an explicit close() on the connection its not your script connection. Reason I'm asking is that I've not been able to duplicate the error message & was trying to figure out what else could be causing it -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Frank" wrote: Quote: > I guess I don't really understand the question. When I first run this > script, I get the error below. When I rerun this script, I don't get the > error. Before I do the first execution of this script, I do a "sp_who2" in > SQLServer and kill all processes that has the DB open. Does that help? > > Thanks, > > > > "RichS" wrote: > Quote: > > It doesn't seem to be your script as you have a $conn.Close() in it. What > > else do you have running that could have an open connection? > > -- > > Richard Siddaway > > Please note that all scripts are supplied "as is" and with no warranty > > Blog: http://richardsiddaway.spaces.live.com/ > > PowerShell User Group: http://www.get-psuguk.org.uk > > > > > > "Frank" wrote: > > Quote: > > > Hi, > > > > > > I have a script which gathers information from a SQLServer table but it > > > errors on the first execution. On subsequent calls, there is no errors and > > > executes fine. I think this may be due to a process which starts and listens > > > for other calls from SQLServer. Does anyone know how to resolve this? Here > > > is the script: > > > > > > $DB = "server=sqlhost;integrated security=true;database=test" > > > $conn = new-object System.Data.SqlClient.SqlConnection > > > $conn.ConnectionString = $DB > > > $conn.Open() > > > $cmd = new-object System.Data.SqlClient.SqlCommand > > > $cmd.Connection=$conn > > > > > > $cmd.CommandText=" > > > SELECT * from notes" > > > $rdr = $cmd.ExecuteReader() > > > While($rdr.Read()){ > > > write-output "$($rdr['notes_id'])" > > > write-output "$($rdr['notes'])" > > > } > > > $conn.Close() > > > ============================================= > > > > > > Here is the error: > > > > > > [D:\scp]: ./f.ps1 > > > Exception calling "ExecuteReader" with "0" argument(s): "A transport-level > > > error has occurred when sending the request to the server. (provider: TCP > > > Provider, error: 0 - An existing connection was forcibly closed by the remote > > > host.)" > > > At D:\scp\f.ps1:13 char:26 > > > + $rdr = $cmd.ExecuteReader( <<<< ) > > > You cannot call a method on a null-valued expression. > > > At D:\scp\f.ps1:15 char:16 > > > + While($rdr.Read( <<<< )){ > > > ============================== > > > > > > Thanks in advance, > > > > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Typed datasets and table table adapters components not showing inToolbox | .NET General | |||
| how do you create a dynamic table/pivot table | .NET General | |||
| connect to paradox db from sqlserver database table | .NET General | |||
| Execution problem | PowerShell | |||
| Wacom table and sleep problem | Vista performance & maintenance | |||