Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Update: Fixed as described here: http://weblogs.asp.net/kencox/archive/2008/02/25/fixed-oracle-11g-and-sqldatasource-the-ugly-ora-01036-illegal-variable-name-number-issue.aspx 

 ----

I've created a short video to explain my problem with Oracle and SqlDataSource. If you'd rather watch than read, go see the video.

I'm trying to do some extremely simple drag and drop development in Visual Web Developer 2008 with the Oracle 11g database and ODP.NET. According to Oracle, "The data provider can be used with the latest .NET Framework 3.5 version. "

The SELECT statement works fine, but any attempt to use UPDATE via the SQLDataSource UpdateCommand nets me the infamous 'ORA-01036: illegal variable name/number'  error.

I wouldn't mind using one of my MSDN Support Incidents to have Microsoft take a look at this issue, but I'm not sure the problem is Microsoft's. It seems like Oracle is doing a poor job in its Visual Studio integration.

Question: Has anyone successfully used an UpdateCommand statement in SQLDataSource against Oracle 11g? If so, let me know!

Below, you see the entire code as generated in Visual Web Developer 2008. To see it in action, check the video.

Ken

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1" 
            EmptyDataText="There are no data records to display.">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="ACCOUNTID" HeaderText="ACCOUNTID" 
                    SortExpression="ACCOUNTID" />
                <asp:BoundField DataField="ACCOUNTNAME" HeaderText="ACCOUNTNAME" 
                    SortExpression="ACCOUNTNAME" />
                <asp:BoundField DataField="ACCOUNTLOCATION" HeaderText="ACCOUNTLOCATION" 
                    SortExpression="ACCOUNTLOCATION" />
                <asp:BoundField DataField="ACCOUNTPHONE" HeaderText="ACCOUNTPHONE" 
                    SortExpression="ACCOUNTPHONE" />
                <asp:BoundField DataField="ACCOUNTCONTACT" HeaderText="ACCOUNTCONTACT" 
                    SortExpression="ACCOUNTCONTACT" />
                <asp:BoundField DataField="ACCOUNTWEBSITE" HeaderText="ACCOUNTWEBSITE" 
                    SortExpression="ACCOUNTWEBSITE" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" 
            ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>" 
            SelectCommand="SELECT &quot;ACCOUNTID&quot;, &quot;ACCOUNTNAME&quot;, &quot;ACCOUNTLOCATION&quot;, &quot;ACCOUNTPHONE&quot;, &quot;ACCOUNTCONTACT&quot;, &quot;ACCOUNTWEBSITE&quot; FROM &quot;ACCOUNTS&quot;" 
            UpdateCommand="UPDATE ACCOUNTS SET ACCOUNTLOCATION = 'This Place' WHERE (ACCOUNTID = 4)">
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
//////////
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
Published Sunday, February 24, 2008 12:06 PM by Ken Cox [MVP]

Comments

# Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue - WebLog of Ken Cox

Pingback from  Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue - WebLog of Ken Cox

# The ugly 'ORA-01036: illegal variable name/number' Issue

Monday, February 25, 2008 7:59 AM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Monday, February 25, 2008 8:00 AM by Mark Wisecarver

Thanks Ken.

I migrated an Oracle world to SQL Server for Siemens and am still recovering from that experience. ;-)

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Friday, March 14, 2008 4:41 PM by Mebeti Dosso

I am using oracle 11g and I wrote this sample code to test the update with sqldatasource. It works successfully. I have the following i addition to your settings:

1. <UpdateParameters>

2. UpdateCommandType="Text"

3. ConflictDetection="OverwriteChanges"

Below is my code. No code behind

<asp:GridView ID="GridView1" AllowSorting="true" AllowPaging="true" Runat="server" Width="400px"

       DataSourceID="SqlDataSource1" AutoGenerateEditButton="true" DataKeyNames="request_id"

       AutoGenerateColumns="False">

       <Columns>

         <asp:BoundField ReadOnly="true" HeaderText="ID" DataField="request_id" SortExpression="request_id" />

         <asp:BoundField HeaderText="Description" DataField="Description" SortExpression="Description" />          

       </Columns>

     </asp:GridView>

     <asp:SqlDataSource ID="SqlDataSource1" Runat="server" SelectCommand="SELECT request_id, Description FROM picklist_request"

       ConflictDetection="OverwriteChanges" UpdateCommandType="Text" SelectCommandType="text"

       UpdateCommand="UPDATE picklist_request SET Description = :Description WHERE request_id = :Request_ID"

       ConnectionString="<%$ ConnectionStrings:LibraryConnectionMS %>" ProviderName="<%$ ConnectionStrings:LibraryConnectionMS.ProviderName %>">

       <UpdateParameters>

           <asp:Parameter Name="Description"  Type="String" />

           <asp:Parameter Name="Request_ID" Type="int32" />

       </UpdateParameters>    

    </asp:SqlDataSource>

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Friday, May 02, 2008 9:07 AM by vesile.taskiran@ttgint.com

i have exactly the same problem.Could you find the solution?

regards

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Friday, May 09, 2008 7:17 PM by xyz

1- Dont use SqlDataSource

Dont use OracleProvider

if you use OracleProvider

"I would recommend using Oracle Developer Tools (ODT) for VS and ODP.NET since these products are much better integrated with .NET and Oracle.   ODP.NET uses Oracle.DataAccess.Client namespace. System.Data.OracleClient belongs to the MS provider for Oracle, which Mark pointed out. If you drag and drop DB objects using ODT, it will generate ODP.NET code for you (and give you more data source wizard options as well).

  - You can download the latest 11g version of ODP.NET and ODT here:   www.oracle.com/.../index.html

2- Dont use vizard for bindings and if it is possible use DataGrid like , I think if it is usefull below:

           <asp:UpdatePanel runat="server" ID="UpdatePanel2">

               <ContentTemplate>

                   <table width="600">

                       <tr>

                           <td valign="middle">

                               Seri No</td>

                           <td>

                               :</td>

                           <td valign="middle">

                               <asp:TextBox ID="txtSeriNo" runat="server" CssClass="TextBox"></asp:TextBox><asp:Button ID="Insertt" Text="Insertt"

                                   runat="server" OnClick="Insertt_Click" CausesValidation="False" CssClass="Buton" />

                               <asp:Label ID="lblError" runat="server" Font-Names="Verdana" Font-Size="X-Small"></asp:Label></td>

                       </tr>

                       <tr>

                           <td colspan="3" align="left" style="font-family: Verdana; font-size: small;">

                               <asp:DataGrid ID="grdDataGrid" Font-Size="X-Small" runat="server" AllowPaging="false"

                                   AllowSorting="false" AutoGenerateColumns="False" CellPadding="2" CellSpacing="0"

                                   ForeColor="#333333" GridLines="Vertical" Width="539px" OnItemCommand="grdDataGrid_ItemCommand"

                                   BorderStyle="Solid" BorderWidth="1px" OnSelectedIndexChanged="grdDataGrid_SelectedIndexChanged">

                                   <FooterStyle BackColor="#507CD1" Font-Bold="False" ForeColor="White" />

                                   <EditItemStyle BackColor="#2461BF" />

                                   <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="False" ForeColor="#333333" />

                                   <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

                                   <AlternatingItemStyle BackColor="White" Font-Size="X-Small" />

                                   <ItemStyle BackColor="#EFF3FB" Font-Size="X-Small" />

                                   <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Size="X-Small" />

                                   <Columns>

                                       <asp:BoundColumn DataField="SERIAL_NO" HeaderText="Seri No"></asp:BoundColumn>

                                       <asp:BoundColumn DataField="DEVICE" HeaderText="Device"></asp:BoundColumn>

                                       <asp:BoundColumn DataField="MODEL" HeaderText="Type"></asp:BoundColumn>

                                       <asp:TemplateColumn>

                                           <ItemTemplate>

                                               <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Dell" Text="Dell" CausesValidation="false"></asp:LinkButton>

                                           </ItemTemplate>

                                       </asp:TemplateColumn>

                                   </Columns>

                               </asp:DataGrid>

                           </td>

                       </tr>

                   </table>

               </ContentTemplate>

           </asp:UpdatePanel>

And in the Code behind Section java script or C# codes

like (allways you think) below:

   protected void grdDataGrid_ItemCommand(object source, DataGridCommandEventArgs e)

   {

       tbProduct = (DataTable)Session["Product"];

       tbProduct.Rows.RemoveAt(e.Item.ItemIndex);

       grdDataGrid.DataSource = tbProduct;

       grdDataGrid.DataBind();

       Session["Product"] = tbProduct;

   }

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Thursday, October 30, 2008 12:37 AM by Rupesh Kumar

I have the same problem of getting an exception ORA 01036 illegal variable name/number and i am using oracle 8i, updation works fine if I give the update command and select command in the "DESIGN MODE" but it gives above mentioned exception when i code the command in the code behind page. Can anybody help?

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Sunday, November 09, 2008 6:31 AM by Adel

Hi guys,

just do the following

change the sqldatasourse property from ConflictDetection="CompareAllValues"  to  ConflictDetection="OverwriteChanges

good luck

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Wednesday, March 18, 2009 7:48 PM by wrociu

I had similar problem today ...

I was trying to make a simple code to see how connection to Oracle works ...

this is how my code looked like :

OracleCommand insCom = new OracleCommand("INSERT INTO pomoctechniczna VALUES(1,1,:Cat,:Sub,"

               + ":Opis,1)" , DataBaseCon);

           insCom.Parameters.Add(":Cat", OracleType.Number,11);

           insCom.Parameters[":Cat"].Value = Convert.ToDecimal(categoryList.SelectedItem.Value);

           insCom.Parameters.Add(":Sub", OracleType.Number, 11);

           insCom.Parameters[":Sub"].Value = Convert.ToDecimal(subjectList.SelectedItem.Value);

           insCom.Parameters.Add(":Opis", OracleType.VarChar, 50);

           insCom.Parameters[":Opis"].Value = descriptionTextBox.Text;

I had this "ORA-01036: illegal variable name/number "

and this is how it looks like now :

OracleCommand insCom = new OracleCommand("BEGIN INSERT INTO pomoctechniczna VALUES(1,1,:Cat,:Sub,"

               + ":Opis,1); END;" , DataBaseCon);

And now it works ... Anonymous block must be used ( BEGIN ... END ) ... the prefix really doesn't matter :)

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Thursday, September 30, 2010 11:10 AM by hugonne

Because you're using the Oracle provider shipped with .NET (System.Data.OracleCliente), and it uses ExecuteNonQuery underneath, you might have to surround your UPDATE clause with a BEGIN and END, to make it an anonymous block. Something like this:

UpdateCommand="  

BEGIN  

UPDATE ACCOUNTS SET ACCOUNTLOCATION = 'This Place' WHERE (ACCOUNTID = 4)

END

"

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Tuesday, July 05, 2011 4:31 AM by JC

Another way this bug can happen in oracle 10 with PL/SQL:

starting a comment with -- which contains code/variables. Using /* */ for the comment makes the error dissappear

# re: Oracle 11G and SqlDataSource: The ugly 'ORA-01036: illegal variable name/number' Issue

Monday, January 09, 2012 7:36 AM by Subhasis

I am using it in below format and it works for me:

===== aspx ====

      <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConflictDetection="OverwriteChanges"

           ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

           ProviderName="System.Data.OracleClient"

...

           InsertCommand="INSERT INTO PROBLEM

                          (NAME, PROBLEMTEXT, PROBLEMTYPE, DESCRIPTION, EVENTID)

                          VALUES (:NAME, :PROBLEMTEXT, :PROBLEMTYPE, :DESCRIPTION, :EVENTID)"

==== aspx.cs ====

   protected void GridView3_RowAdding(object sender,

                   GridViewUpdateEventArgs e)

   {

       if (e.RowIndex > 0)

           return; // RowIndex=0 is the row we want to insert

       System.Collections.Hashtable h =

                   new System.Collections.Hashtable();

       foreach (System.Collections.DictionaryEntry x in e.NewValues)

       {

           h[x.Key] = x.Value;

           SqlDataSource3.InsertParameters[x.Key.ToString()].DefaultValue = x.Value.ToString();

       }

       SqlDataSource3.Insert();

====

Leave a Comment

(required) 
(required) 
(optional)
(required)