D8 odd SqlConnection error

From: David Godwin (dagodwin_at_tagfolio.com)
Date: 01/22/04

  • Next message: Lee Grissom: "Re: D8: Beginning ADO.NET App"
    Date: Thu, 22 Jan 2004 13:16:53 -0500
    
    

    I'm beginning to work with the new D8 using winforms and came across a
    peculiar issue. Take the following code, which loads a connection string
    and uses it to open a SqlConnection object:

    procedure CreateDBConnection(var NewConnection: SqlConnection; const DBName:
    string);
    var
      conMaster: SqlConnection;
      cmd: SqlCommand;
      drData: SqlDataReader;
      strSQL, strConnect: string;
    begin
      cmdTag := nil;
      drData := nil;
      strConnect := '';

      // conMaster is setup here...

      try
        try

          // strSQL is generated here...

          cmd := SqlCommand.Create(strSQL, conMaster);
          drData := cmd.ExecuteReader;
          if drData.Read then
            strConnect := drData.GetString(0);

          NewConnection := SqlConnection.Create(strConnect);
          NewConnection.Open;

        except
          on E:Exception do
            raise Exception.Create('[CreateDBConnection] ' + E.Message);
        end;
      finally
        if drData <> nil then drData.Free;
        if cmd <> nil then cmd.Free;
        conMaster.Free;
      end;
    end;

    If for some reason strConnect is invalid, an exception is raised out just as
    would be expected. However, when strConnect is valid, the Create and Open
    statements execute correctly but control passes to the exception handler
    with E.Message equalling "function call terminated by exception". To make
    this even stranger, no exception is raised out of the procedure!
    NewConnection is correctly initialized, and everything works as normal.

    Even though everything works, I'm left feeling like something is broken.
    Does anyone have any idea what's going on?

    Thanks in advance,
    David


  • Next message: Lee Grissom: "Re: D8: Beginning ADO.NET App"

    Relevant Pages

    • D8 odd SqlConnection error
      ... which loads a connection string ... procedure CreateDBConnection(var NewConnection: SqlConnection; const DBName: ... If for some reason strConnect is invalid, an exception is raised out just as ...
      (borland.public.delphi.language.objectpascal)
    • Re: Must declare the scalar variable "@" - paramaterized sqlclient insert - HELP!!
      ... Dim iIndex1 As Integer ... String, rowsAffected As Integer ... 'sqlCMD.Connection= sqlConnection ... Catch ex As Exception ...
      (microsoft.public.dotnet.framework.adonet)
    • RE: Detailed ASP.Net info not displaying in browser
      ... HTTP 500 page when an exception is thrown from the web service. ... at VOSE.Data.DataRequest.dr_DB2Process.DeleteCommRows(String company, String ... objQueue, tOrderManagementIndicator omindicator, Int32 intTriggerId) in ... Microsoft Online Community Support ...
      (microsoft.public.dotnet.xml)
    • RE: Detailed ASP.Net info not displaying in browser
      ... HTTP 500 page when an exception is thrown from the web service. ... at VOSE.Data.DataRequest.dr_DB2Process.DeleteCommRows(String company, String ... objQueue, tOrderManagementIndicator omindicator, Int32 intTriggerId) in ... Microsoft Online Community Support ...
      (microsoft.public.dotnet.xml)
    • Re: App_data - ASPNETDB.MDF
      ... is only because I want my site work, without exception. ... Server Error in '/' Application. ... serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 ...
      (microsoft.public.dotnet.framework.aspnet)