[Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

Discussion in 'Databases' started by mhebner, Dec 4, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi, I'm currently working on a web form that accepts user input and when the submit button is clicked it then sends the user form supplied data and inserts it as a new record in a SQL 2k DB. The problem I'm running into is when I complete the form and click on the submit button, I get the following error message:

    Microsoft OLE DB Provider for ODBC Drivers error '80004005'

    [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

    /AddProducts/confirm.asp, line 4

    I've double checked the file/folder and db permissions and everything seems in order. Basically it consists of a web form (form.asp) and another page that does the insert (confirm.asp). Below is the code for the confirm.asp page. Let me know if you need me to post the code for the form.asp page. Any help is very much appreciated. Thanks in advance.

    code for confirm.asp:
    --------------------------

    <%
    If Len(Request.Form) > 0 Then
    set objConn = CreateObject('Adodb.Connection')
    objConn.Open 'DSN=DB_231079_datapreserve_sqlConn;uid=products;pwd=Pr0ducts'
    set objRS = objConn.Execute('SET NOCOUNT ON; INSERT INTO dbo.product (name, description, price, billingCycle, minRetention, maxRetention, freeQuantity, inventoryNumber, doQuantityQuestion, qtyMinValue, qtyMaxValue, qtyIncrement, productGroupId, productAppearanceID, organizationId, IsMultiplier, IsOverage, IsActive) VALUES ('' & Replace(Request.Form('name'),''','''') & '', '' & Replace(Request.Form('description'),''','''') & ', '' & Replace(Request.Form('price'),''','''')& ', '' & Replace(Request.Form('billingCycle'),''','''') & ' , '' & Replace(Request.Form('minRetention'),''','''')&', '' & Replace(Request.Form('maxRetention'),''','''')&', '' & Replace(Request.Form('freeQuantity'),''','''')&', '' & Replace(Request.Form('inventoryNumber'),''','''')&', '' & Replace(Request.Form('doQuantityQuestion'),''','''')&', '' & Replace(Request.Form('qtyMinValue'),''','''')&', '' & Replace(Request.Form('qtyMaxValue'),''','''')&', '' & Replace(Request.Form('qtyIncrement'),''','''')&', '' & Replace(Request.Form('productGroupId'),''','''')&', '' & Replace(Request.Form('productAppearanceId'),''','''')&', '' & Replace(Request.Form('organizationId'),''','''')&', '' & Replace(Request.Form('IsMultiplier'),''','''')&', '' & Replace(Request.Form('IsOverage'),''','''')&', '' & Replace(Request.Form('IsActive'),''','''') & ''); SELECT @@IDENTITY; SET NOCOUNT OFF;')
    If Not(objRS.Eof) Then
    Dim NewID : NewID = objRS(0)
    End If
    set objRS = Nothing
    objConn.Close
    set objConn = Nothing
    End If
    %>
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    This is a known bug with ODBC. I recommend you change your code to NOT use ODBC but rather OleDB.

    Change this line to

    objConn.Open "DSN=DB_231079_datapreserve_sqlConn;uid=products;pwd=Pr0ducts"

    ---->

    objConn.Open ""Provider=SQLOLEDB;Data Source=YOURDBSERVER;Initial Catalog=YOURDBNAME;User Id=YOURDBUSERID;Password=YOURDBPASSWORD;"

    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. >Thank you for the help. I made the changes but now I'm getting a
    > syntax error near line 10 (price field). Here's the error:
    >
    > Microsoft OLE DB Provider for SQL Server error '80040e14'
    >
    > Line 1: Incorrect syntax near '12.00'.
    >
    > /AddProducts/confirm.asp, line 10
    >
    > (The '12.00' is the amount I entered into the price field in the web form).
    >
    > I'm stumped onthis one and can't seem to find the error. Here's the updated code:
    >
    > Confirm.asp
    > ----------------
    > <%
    > Dim cnnSimple ' ADO connection
    > Dim rstSimple ' ADO recordset
    > Set cnnSimple = Server.CreateObject("ADODB.Connection")
    > ' DSNLess
    > If Len(Request.Form) > 0 Then
    > cnnSimple.Open "Provider=SQLOLEDB;Data Source=mssql07.discountasp.net;" _
    > &amp; "Initial Catalog=DB_231079_datapreserve;User
    > Id=user;Password=password;" _
    > &amp; "Connect Timeout=15;Network Library=dbmssocn;"
    > Set rstSimple = cnnSimple.Execute("SET NOCOUNT ON; INSERT INTO
    > dbo.product (name, description, price, billingCycle, minRetention,
    > maxRetention, freeQuantity, inventoryNumber, doQuantityQuestion,
    > qtyMinValue, qtyMaxValue, qtyIncrement, productGroupId,
    > productAppearanceID, organizationId, IsMultiplier, IsOverage,
    > IsActive) VALUES ('" &amp;
    > Replace(Request.Form("name"),"'","''") &amp; "', '" &amp;
    > Replace(Request.Form("description"),"'","''") &amp; ", '" &amp;
    > Replace(Request.Form("price"),"'","''")&amp; ", '" &amp;
    > Replace(Request.Form("billingCycle"),"'","''") &amp; " , '" &amp;
    > Replace(Request.Form("minRetention"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("maxRetention"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("freeQuantity"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("inventoryNumber"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("doQuantityQuestion"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("qtyMinValue"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("qtyMaxValue"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("qtyIncrement"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("productGroupId"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("productAppearanceId"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("organizationId"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("IsMultiplier"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("IsOverage"),"'","''")&amp;", '" &amp;
    > Replace(Request.Form("IsActive"),"'","''") &amp; "'); SELECT @@IDENTITY;
    > SET NOCOUNT OFF;")
    > If Not(rstSimple.Eof) Then
    > Dim NewID : NewID = rstSimple(0)
    > End If
    > set rstSimple = Nothing
    > rstSimple.Close
    > set rstSimple = Nothing
    > End If
    > %>
    >
    > Thanks again for your help. I really appreciate it. Take care and please let me know if you need anyadditional information.
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    it's really hard to see from what you posted. I would write the query string into a str variable and dump it out to the screen and examine it.


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. ok, I'll try that and hopefully can get it working. Thanks for your response. Take care.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page