Friday, February 24, 2012
Debugging Stored Procedure
I thnk its thru VS, pls let me know the details or any references.
Thanks
--
RKNETcheck this link..
http://sqljunkies.com/WebLog/nielsb...ategory/99.aspx
Debugging Stored Proc
When I go to debug any SP thru Object browser in query analyser ... it
starts well ... takes all the required parameters to begin ... but when I
click on execute button, it completes the SP execution immediately. It does
not allow to use functions like Step into, Step over etc ... Why does this
happen?
Because of this, my main purpose of debugging any SP, does not get satisfied
.
Pls Help."Krishnapra
Paralikar" <Krishnapra
Paralikar@.discussions.microsoft.com> wrote in message
news:9DDB8999-67C1-44C8-ADD6-B2979892E612@.microsoft.com...
> When I go to debug any SP thru Object browser in query analyser
http://www.sql-server1.org/detail-7330883.html
Tuesday, February 14, 2012
Debug Error - Object variable or With block variable not set -
I keep getting this debug error, see my code below, I have gone thru it time and time agian and do not see where the problem is. I have checked and have no NULL values that I'm trying to write back.
~~~~~~~~~~~
Error:
System.NullReferenceException was unhandled by user code
Message="Object variable or With block variable not set."
Source="Microsoft.VisualBasic"
~~~~~~~~~~~~
My Code
Dim DBConnAs SqlConnection
Dim DBAddAsNew SqlCommand
Dim strConnectAsString = ConfigurationManager.ConnectionStrings("ProtoCostConnectionString").ConnectionString
DBConn =New SqlConnection(strConnect)
DBAdd.CommandText ="INSERT INTO D12_MIS (" _
&"CSJ, EST_DATE, RECORD_LOCK_FLAG, EST_CREATE_BY_NAME, EST_REVIEW_BY_NAME, m2_1, m2_2_date, m2_3_date, m2_4_date, m2_5, m3_1a, m3_1b, m3_2a, m3_2b, m3_3a, m3_3b" _
&") values (" _
&"'" & Replace(vbCSJ.Text,"'","''") _
&"', " _
&"'" & Replace(tmp1Date,"'","''") _
&"', " _
&"'" & Replace(tmpRecordLock,"'","''") _
&"', " _
&"'" & Replace(CheckedCreator,"'","''") _
&"', " _
&"'" & Replace(CheckedReviewer,"'","''") _
&"', " _
&"'" & Replace(vb2_1,"'","''") _
&"', " _
&"'" & Replace(tmp2Date,"'","''") _
&"', " _
&"'" & Replace(tmp3Date,"'","''") _
&"', " _
&"'" & Replace(tmp4Date,"'","''") _
&"', " _
&"'" & Replace(vb2_5,"'","''") _
&"', " _
&"'" & Replace(vb3_1a,"'","''") _
&"', " _
&"'" & Replace(vb3_1b,"'","''") _
&"', " _
&"'" & Replace(vb3_2a,"'","''") _
&"', " _
&"'" & Replace(vb3_2b,"'","''") _
&"', " _
&"'" & Replace(vb3_3a,"'","''") _
&"', " _
&"'" & Replace(vb3_3b,"'","''") _
&"')"
DBAdd.Connection = DBConn
DBAdd.Connection.Open()
DBAdd.ExecuteNonQuery()
DBAdd.Connection.Close()
Has nothing to do with NULL values, it's a null reference. In better VB-speak, you've accessed a method or property on an object that you haven't initialized.
For example:
Dim conn as sqlconnection
conn.open
Notice, conn was never set to a sqlconnection, hence, it's nothing (Nothing is vb-speak for C#/C++'s null).
My guess is that you don't actually have your web.config set up correctly. More specifically, you don't have a connection string named "ProtoCostConnectionString" in the connectionstrings section. Note, that is NOT the same as the appsettings section.
Also, you really should use a parameterized query, and if you are going to be concatenating more than a few lines of strings, you'd be much better off using the stringbuilder class if you absolutely MUST continue using string concatenation as how you build your SQL commands.
|||Thanks, I will rewrite this procedure and will use "parameterized query" instead of the string variable.