SQL Error caused by .NET Framework incompatibility

Discussion in 'ASP .Net' started by Edward, Jul 18, 2003.

  1. Edward

    Edward Guest

    Our app was built on VS using .NET Framework version 1.0.3705 It
    worked fine until last week when the SysAdmin installed W2k SP4 which,
    it appears, installs the .NET Framework version 1.1 This has broken
    our code. It was failing with the error :

    "Syntax error converting from a character string to uniqueidentifier."

    The SQL in question was, in retrospect, probably not very well formed:

    "SELECT tblContacts.*, tblCompanies.fldCompanyName FROM tblContacts
    INNER JOIN tblCompanies ON tblContacts.fldCompanyID =
    tblCompanies.fldCompanyId WHERE (fldContactID = '" & CType(pRecordID,
    String) & "')"

    If the value of pRecordID was empty, the actual SQL was

    "SELECT tblContacts.*, tblCompanies.fldCompanyName FROM tblContacts
    INNER JOIN tblCompanies ON tblContacts.fldCompanyID =
    tblCompanies.fldCompanyId WHERE (fldContactID = '')"


    The function that used this SQL was:

    Public Overloads Shared Function ExecuteReader(ByVal connectionString
    As String, ByVal commandType As CommandType, ByVal commandText As
    String) As SqlDataReader

    In the previous (working) version this simply returned Nothing which
    was fine - we would test for Nothing, and deduce that this meant a new
    record.

    Under the new version of .NET Framework, this throws the above error.

    Just a heads up if you are interested. We were under the impression
    that Visual Studio targetted particular Frameworks, and that versions
    1.0.3705 and 1.1 were designed to sit together side by side. Seems
    not.

    Best

    Edward
     
    Edward, Jul 18, 2003
    #1
    1. Advertisements

  2. My suggestion is this. Alter the statement to something like:

    Dim sql As String = "SELECT tblContacts.*, tblCompanies.fldCompanyName FROM
    tblContacts
    INNER JOIN tblCompanies ON tblContacts.fldCompanyID =
    tblCompanies.fldCompanyId WHERE (fldContactID = @fldContactID)"

    Then, set up a parameter for @fldContactID using a SQLGuid (assuming this is
    a uniqueIdentifier from the error message):

    Imports System.Data.SqlTypes

    ....

    Dim sg As SqlGuid

    Try
    sg = new SqlGuid(pRecordId)
    Catch
    If pRecordId.Trim() = "" Then
    sg = SqlGuid.Null
    Else
    'You figure how to handle garbage here
    End If
    End Try

    'Set up param
    cmd.Parameters.Add("@fldContactId", sg)

    You now can properly handle a NULL rather than have the Framework cast an
    empty as a NULL.

    Hope this helps.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA
    Author: ADO.NET and XML: ASP.NET on the Edge

    ****************************************************************************
    ****
    Think Outside the Box!
    ****************************************************************************
    ****
    "Edward" <> wrote in message
    news:...
    > Our app was built on VS using .NET Framework version 1.0.3705 It
    > worked fine until last week when the SysAdmin installed W2k SP4 which,
    > it appears, installs the .NET Framework version 1.1 This has broken
    > our code. It was failing with the error :
    >
    > "Syntax error converting from a character string to uniqueidentifier."
    >
    > The SQL in question was, in retrospect, probably not very well formed:
    >
    > "SELECT tblContacts.*, tblCompanies.fldCompanyName FROM tblContacts
    > INNER JOIN tblCompanies ON tblContacts.fldCompanyID =
    > tblCompanies.fldCompanyId WHERE (fldContactID = '" & CType(pRecordID,
    > String) & "')"
    >
    > If the value of pRecordID was empty, the actual SQL was
    >
    > "SELECT tblContacts.*, tblCompanies.fldCompanyName FROM tblContacts
    > INNER JOIN tblCompanies ON tblContacts.fldCompanyID =
    > tblCompanies.fldCompanyId WHERE (fldContactID = '')"
    >
    >
    > The function that used this SQL was:
    >
    > Public Overloads Shared Function ExecuteReader(ByVal connectionString
    > As String, ByVal commandType As CommandType, ByVal commandText As
    > String) As SqlDataReader
    >
    > In the previous (working) version this simply returned Nothing which
    > was fine - we would test for Nothing, and deduce that this meant a new
    > record.
    >
    > Under the new version of .NET Framework, this throws the above error.
    >
    > Just a heads up if you are interested. We were under the impression
    > that Visual Studio targetted particular Frameworks, and that versions
    > 1.0.3705 and 1.1 were designed to sit together side by side. Seems
    > not.
    >
    > Best
    >
    > Edward
     
    Cowboy \(Gregory A. Beamer\), Jul 18, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?R290ZG90TmV0?=

    Unspecified error | FrameWork 1.1 | ASP.net | SQL 2000

    =?Utf-8?B?R290ZG90TmV0?=, Nov 7, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    977
    =?Utf-8?B?R290RG90TmV0?=
    Nov 10, 2003
  2. henry
    Replies:
    1
    Views:
    502
    =?Utf-8?B?RGF2aWQgQ29lLCBNQ1A=?=
    Feb 23, 2004
  3. moi
    Replies:
    3
    Views:
    4,275
    quaiser_ali
    Sep 26, 2008
  4. pizza
    Replies:
    1
    Views:
    689
    Eliyahu Goldin
    Mar 8, 2007
  5. Mark C
    Replies:
    0
    Views:
    1,131
    Mark C
    Nov 5, 2007
  6. Rachel
    Replies:
    1
    Views:
    1,053
    Rachel
    Dec 10, 2007
  7. quaiser_ali
    Replies:
    0
    Views:
    2,473
    quaiser_ali
    Sep 26, 2008
  8. ald
    Replies:
    3
    Views:
    370
    Axel Dahmen
    Dec 21, 2003
Loading...