title: Invalid character value for cast specification sometimes
body: <p>Im currently investigating a bug that just happens sometimes. I have not been able to see any patterns to the behavior yet. I have a vb6 com+-application that communicates with the server. </p>
  
  <pre><code>Err: Invalid character value for cast specification. (&amp;H80040E21)
  Src: Microsoft OLE DB Provider for SQL Server
  Stacktrace:
  GetClientRS("SELECT * FROM Visit where GUID=?")
  GetVisit("('{5EF4A26A-0909-4371-97F7-A2597CB7ADE3}')")
  </code></pre>
  
  <p>This is the error that happens sometimes. Maybe 1-2 times for every 5 times it is called. I have tried a trace in SQL server profiler but I am unable to detect any errors. </p>
  
  <p>Does anyone have any ideas I could try? </p>
  
  <pre><code>Edit:
  Code for calling the command:
  GetVisit:
      Set cmd = CreateCommand("SELECT * FROM dbo.per_Visit WHERE GUID=?")
      cmd.Parameters.Append cmd.CreateParameter(, adGUID, , , SafeGUID(sGUID))
  
      Set GetVisit = GetClientRS(cmd, True)
  
  SafeGUID:
       If Mid$(sGUID, 1, 1) &lt;&gt; "{" Then                                  
           sGUID = "{" &amp; sGUID &amp; "}"                                     
      End If
  
     SafeGUID = sGUID
  </code></pre>