|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
Hi all, I have been stucked with this for quite a while. I have a script:
Dim sqlConnStr As String = "Data Source=" & RdVarStr("DB_Server_Name") & ";Initial Catalog=" & RdVarStr("DB_Init_Cat") & ";Integrated Security=True;" Dim rowCounter As Integer Using sqlConn As New Data.SqlClient.SqlConnection(sqlConnStr) sqlConn.Open() Using sqlCmd As New Data.SqlClient.SqlCommand("SELECT Count(*) from Target where WORKED_HRS >= (select VALUE from CONFIG where MODULE = 'SSIS TACSReport' and [KEY]= 'Var_WorkHrs_Limit') +':00'", sqlConn) Dim sqlDtReader As Data.SqlClient.SqlDataReader sqlDtReader = sqlCmd.ExecuteReader() rowCounter = sqlDtReader.GetInt32(0) sqlDtReader.Close() End Using End Using Return rowCounter
It seems simple and i tot this is it, however i keep getting error:
Invalid attempt to read when no data is present.
But i am sure there is value as i did a sqlDtReader.Read to check. What wrong and what to do?
Thanks, 10e5x
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Yesterday @ 9:39 AM
Points: 4,247,
Visits: 9,500
|
|
Have you tried setting a breakpoint and debugging line by line? It might illuminate the problem.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
HI phil, thanks for helping once again. I will trying what u suggest later, currently out of office. But i guess the problem is most likely to do with getting the count(*) and store it as an int in an int variable
rowCounter = sqlDtReader.GetInt32(0)
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Yesterday @ 9:39 AM
Points: 4,247,
Visits: 9,500
|
|
..which you will quickly diagnose when running in debug. Sounds like the datareader may not be getting populated at all.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
Hi phil, I heed ur advice and did a debug. It was strange it doesnt return me any data. Hence i read through my script and realize it may be due to that the prog did not read it row by row even though i am only expecting 1 row with 1 column result. Therefore i added in a While(reader.read()).... cycle and it WORKS. although i do not uds why i need a loop when it is only one row, but it does solved my problem.
Thanks for your help.
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Yesterday @ 9:39 AM
Points: 4,247,
Visits: 9,500
|
|
10e5x (12/19/2012) Hi phil, I heed ur advice and did a debug. It was strange it doesnt return me any data. Hence i read through my script and realize it may be due to that the prog did not read it row by row even though i am only expecting 1 row with 1 column result. Therefore i added in a While(reader.read()).... cycle and it WORKS. although i do not uds why i need a loop when it is only one row, but it does solved my problem.
Thanks for your help.
Excellent - I should have noticed that, but well done.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
Hi phil,
Thanks for helping all these while. With all the help from amazing users of this forum, finally i am wrapping up my first project in my new dept. Now i am asked to create a .cmd file to run my SSIS package, which i have not figured out how to. Do u have any guide/article for me to read so i know how to start?
Thanks, 10e5x
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Yesterday @ 8:56 AM
Points: 982,
Visits: 345
|
|
Here is a batch file to execute ssis packages:
the /DECRPYT is where you would put the package password (if there is one) The following illustrates using the 64 bit bit version and the 32 bit version
rem this will be a batch file to call ssis packages rem "C:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTEXEC.exe" /f "C:\Subversion\Test\Test\package.dtsx" /DECRYPT password"
"C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\DTEXEC.exe " /f "C:\Subversion\Test\Test\package.dtsx" /DECRYPT password"
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Saturday, February 02, 2013 11:09 AM
Points: 97,
Visits: 180
|
|
Hi Churlbut,
Thanks for replying, wasnt expecting that but this really explain why this forum is so good. This is my first time working with batch file or cmd file. I dont uds what u tryng to do. U pasted two lines of codes, which goes to which. I am guessing some goes to a notepad file am i right? And as for the path u states, which are the standards, which are dependent on my file location? Just hope i can get that right:)
Thanks, 10e5x
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Yesterday @ 8:44 AM
Points: 4,434,
Visits: 7,218
|
|
Yes, paste the code into notepad, edit it so that it's right for your environment, and save it as a .bat or .cmd file. Make sure the path to the executable is the same as on your computer, and likewise for the .dtsx file. If your package is stored in msdb instead of the file system, you'll have to tweak the command a bit - just search for the syntax for dtexec.exe to find out how to do that.
John
|
|
|
|