Sql Exception in .net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stanley j mroczek

    #1

    Sql Exception in .net

    I read
    "Error Handling in SQL Server - a Background",
    http://www.algonet.se/~sommar/error-handling-I.html and
    "Implementi ng Error Handling with Stored Procedures",
    Nu är det jul hos Telenor med extra bra deals på mobiler, abonnemang, bredband och tv | Telenor


    and made the following changes:

    if I take out the try I still get the error and I know
    how to find whats wrong.

    Please hekp??
    Stan
    -----------------------------------------------------------
    Public Function CSVUpdate(ByVal Name As String, _
    ByVal code As String, _
    ByVal Caption As String, _
    ByVal Price As Integer, _
    ByVal SalePrice As Integer, _
    ByVal id As String, _
    ByVal path As String)

    ' Create Instance of Connection and Command
    Object
    Dim myConnection As SqlConnection = New
    SqlConnection(C onfigurationSet tings.AppSettin gs
    ("ConnectionStr ing"))
    Dim myCommand As SqlCommand = New SqlCommand
    ("Update_CSV ", myConnection)

    ' Mark the Command as a SPROC
    myCommand.Comma ndType =
    CommandType.Sto redProcedure


    ' Add Parameters to SPROC
    Dim parameterName As SqlParameter = New
    SqlParameter("@ Name", SqlDbType.NVarC har, 255)
    parameterName.V alue = Name
    myCommand.Param eters.Add(param eterName)

    Dim parametercode As SqlParameter = New
    SqlParameter("@ code", SqlDbType.NVarC har, 255)
    parametercode.V alue = code
    myCommand.Param eters.Add(param etercode)

    Dim parameterCaptio n As SqlParameter = New
    SqlParameter("@ Caption", SqlDbType.NVarC har, 4000)
    parameterCaptio n.Value = Caption
    myCommand.Param eters.Add(param eterCaption)


    Dim parameterPrice As SqlParameter = New
    SqlParameter("@ Price", SqlDbType.Int, 4)
    parameterPrice. Value = Price
    myCommand.Param eters.Add(param eterPrice)

    Dim parameterSalePr ice As SqlParameter = New
    SqlParameter("@ SalePrice", SqlDbType.Int, 4)
    parameterSalePr ice.Value = SalePrice
    myCommand.Param eters.Add(param eterSalePrice)

    Dim parameterid As SqlParameter = New
    SqlParameter("@ Id", SqlDbType.NVarC har, 255)
    parameterid.Val ue = id
    myCommand.Param eters.Add(param eterid)

    Dim parameterpath As SqlParameter = New
    SqlParameter("@ path", SqlDbType.NVarC har, 255)
    parameterpath.V alue = path
    myCommand.Param eters.Add(param eterpath)

    Dim parametererr As SqlParameter = New
    SqlParameter("@ err", SqlDbType.Int, 4)
    parametererr.Di rection =
    ParameterDirect ion.Output
    myCommand.Param eters.Add(param etererr)

    Try
    ' Open the connection and execute the
    Command
    myConnection.Op en()
    myCommand.Execu teNonQuery()
    Catch myException As SqlException
    Dim errornumber As Integer = CInt
    (parametererr.V alue)
    End Try
    myConnection.Cl ose()

    -----------------------------------------------------------
    -----------------
    CREATE PROCEDURE Update_CSV

    @Name nvarchar(255),
    @code nvarchar(255),
    @Caption nvarchar(4000),
    @Price int,
    @SalePrice int,
    @id nvarchar(255),
    @path nvarchar(255),
    @err int output
    as


    SET NOCOUNT ON

    DECLARE @CountItems int

    SELECT
    @CountItems = Count(*)
    FROM CSV

    WHERE code = @code


    IF @CountItems > 0 /* There are items - update the
    current quantity */

    UPDATE CSV
    SET Name = @Name, code = @code,Id = @id,
    Caption = @Caption, Price = @Price, [Sale-Price] =
    @SalePrice,
    path = @path
    WHERE code = @code

    ELSE /* New entry for this Cart. Add a new record */

    INSERT INTO CSV
    (Name, code, Caption, Price, [Sale-
    Price], path,id)
    VALUES (@Name, @code, @Caption, @Price, @SalePrice,
    @path,@id)

    SELECT @err = @@error if @err <> 0 return @err
    GO
    ---------------------------

  • JohnFol

    #2
    Re: Sql Exception in .net

    What is the error, which line causes it?
    What happens if you run the sproc in query analyzer?


    "stanley j mroczek" <smroczek@si.rr .com> wrote in message
    news:08db01c357 de$b7f81170$a10 1280a@phx.gbl.. .[color=blue]
    > I read
    > "Error Handling in SQL Server - a Background",
    > http://www.algonet.se/~sommar/error-handling-I.html and
    > "Implementi ng Error Handling with Stored Procedures",
    > http://www.algonet.se/~sommar/error-handling-II.html
    >
    > and made the following changes:
    >
    > if I take out the try I still get the error and I know
    > how to find whats wrong.
    >
    > Please hekp??
    > Stan
    > -----------------------------------------------------------
    > Public Function CSVUpdate(ByVal Name As String, _
    > ByVal code As String, _
    > ByVal Caption As String, _
    > ByVal Price As Integer, _
    > ByVal SalePrice As Integer, _
    > ByVal id As String, _
    > ByVal path As String)
    >
    > ' Create Instance of Connection and Command
    > Object
    > Dim myConnection As SqlConnection = New
    > SqlConnection(C onfigurationSet tings.AppSettin gs
    > ("ConnectionStr ing"))
    > Dim myCommand As SqlCommand = New SqlCommand
    > ("Update_CSV ", myConnection)
    >
    > ' Mark the Command as a SPROC
    > myCommand.Comma ndType =
    > CommandType.Sto redProcedure
    >
    >
    > ' Add Parameters to SPROC
    > Dim parameterName As SqlParameter = New
    > SqlParameter("@ Name", SqlDbType.NVarC har, 255)
    > parameterName.V alue = Name
    > myCommand.Param eters.Add(param eterName)
    >
    > Dim parametercode As SqlParameter = New
    > SqlParameter("@ code", SqlDbType.NVarC har, 255)
    > parametercode.V alue = code
    > myCommand.Param eters.Add(param etercode)
    >
    > Dim parameterCaptio n As SqlParameter = New
    > SqlParameter("@ Caption", SqlDbType.NVarC har, 4000)
    > parameterCaptio n.Value = Caption
    > myCommand.Param eters.Add(param eterCaption)
    >
    >
    > Dim parameterPrice As SqlParameter = New
    > SqlParameter("@ Price", SqlDbType.Int, 4)
    > parameterPrice. Value = Price
    > myCommand.Param eters.Add(param eterPrice)
    >
    > Dim parameterSalePr ice As SqlParameter = New
    > SqlParameter("@ SalePrice", SqlDbType.Int, 4)
    > parameterSalePr ice.Value = SalePrice
    > myCommand.Param eters.Add(param eterSalePrice)
    >
    > Dim parameterid As SqlParameter = New
    > SqlParameter("@ Id", SqlDbType.NVarC har, 255)
    > parameterid.Val ue = id
    > myCommand.Param eters.Add(param eterid)
    >
    > Dim parameterpath As SqlParameter = New
    > SqlParameter("@ path", SqlDbType.NVarC har, 255)
    > parameterpath.V alue = path
    > myCommand.Param eters.Add(param eterpath)
    >
    > Dim parametererr As SqlParameter = New
    > SqlParameter("@ err", SqlDbType.Int, 4)
    > parametererr.Di rection =
    > ParameterDirect ion.Output
    > myCommand.Param eters.Add(param etererr)
    >
    > Try
    > ' Open the connection and execute the
    > Command
    > myConnection.Op en()
    > myCommand.Execu teNonQuery()
    > Catch myException As SqlException
    > Dim errornumber As Integer = CInt
    > (parametererr.V alue)
    > End Try
    > myConnection.Cl ose()
    >
    > -----------------------------------------------------------
    > -----------------
    > CREATE PROCEDURE Update_CSV
    >
    > @Name nvarchar(255),
    > @code nvarchar(255),
    > @Caption nvarchar(4000),
    > @Price int,
    > @SalePrice int,
    > @id nvarchar(255),
    > @path nvarchar(255),
    > @err int output
    > as
    >
    >
    > SET NOCOUNT ON
    >
    > DECLARE @CountItems int
    >
    > SELECT
    > @CountItems = Count(*)
    > FROM CSV
    >
    > WHERE code = @code
    >
    >
    > IF @CountItems > 0 /* There are items - update the
    > current quantity */
    >
    > UPDATE CSV
    > SET Name = @Name, code = @code,Id = @id,
    > Caption = @Caption, Price = @Price, [Sale-Price] =
    > @SalePrice,
    > path = @path
    > WHERE code = @code
    >
    > ELSE /* New entry for this Cart. Add a new record */
    >
    > INSERT INTO CSV
    > (Name, code, Caption, Price, [Sale-
    > Price], path,id)
    > VALUES (@Name, @code, @Caption, @Price, @SalePrice,
    > @path,@id)
    >
    > SELECT @err = @@error if @err <> 0 return @err
    > GO
    > ---------------------------
    >[/color]


    Comment

    • stanley mroczek

      #3
      Re: Sql Exception in .net

      i run the program and 188 records are processed before i get this error.

      Server Error in '/' Application.
      ------------------------------------------------------------------------
      --------

      General network error. Check your network documentation.
      Description: An unhandled exception occurred during the execution of the
      current web request. Please review the stack trace for more information
      about the error and where it originated in the code.

      Exception Details: System.Data.Sql Client.SqlExcep tion: General network
      error. Check your network documentation.

      Source Error:


      Line 1865: ' Open the connection and execute the Command
      Line 1866: myConnection.Op en()
      Line 1867: myCommand.Execu teNonQuery()
      Line 1868: myConnection.Cl ose()
      Line 1869:


      Source File: C:\Market\Compo nents\Maintenan ceDB.vb Line: 1867

      Stack Trace:


      [SqlException: General network error. Check your network
      documentation.]
      System.Data.Sql Client.SqlComma nd.ExecuteReade r(CommandBehavi or
      cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
      System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +194
      Market.MK.Maint enanceDB.Produc tUpdate(Int32 ProdIDkey, Int32
      WholesalerId, String prodID, String prodName, String AuctionTitle,
      String prodDescription , String prodImageSmallP ath, String
      prodImageLargeP ath, String RetailPrice, String CostPrice, String
      SalePrice, String revPrice, String IdMetal, String idlength, String
      gramsofgold, String Minimumcarattot alweight, String page, String
      CategoryKey, String Width, String Numberofdiamond s) in
      C:\Market\Compo nents\Maintenan ceDB.vb:1867
      Market.__MaintP roducts.updatec ommandheader(Ob ject sender,
      DataGridCommand EventArgs H) in C:\Market\_Main tProducts.ascx. vb:531

      System.Web.UI.W ebControls.Data Grid.OnUpdateCo mmand(DataGridC ommandEventA
      rgs e) +109
      System.Web.UI.W ebControls.Data Grid.OnBubbleEv ent(Object source,
      EventArgs e) +507
      System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args)
      +26
      System.Web.UI.W ebControls.Data GridItem.OnBubb leEvent(Object source,
      EventArgs e) +100
      System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args)
      +26
      System.Web.UI.W ebControls.Link Button.OnComman d(CommandEventA rgs e)
      +120

      System.Web.UI.W ebControls.Link Button.System.W eb.UI.IPostBack EventHandler
      .RaisePostBackE vent(String eventArgument) +115
      System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
      sourceControl, String eventArgument) +18
      System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
      +138
      System.Web.UI.P age.ProcessRequ estMain() +1258





      Stanley J. Mroczek

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...