A
AlBruAn
I need to persist some data to SQL Server, but I can't for the life of me
figure out why I'm getting an error with each attempt.
The code I'm using is as follows:
SqlTransaction trans;
using (SqlConnection conn = new
SqlConnection(myConn)) //_connectionString))
{
conn.Open();
trans = conn.BeginTransaction();
SqlCommand comm = new SqlCommand("InsertContainerData", conn, trans);
#region unused
//comm.Parameters.Add("@ContainerEID", SqlDbType.UniqueIdentifier);
//comm.Parameters.Add("@ContainerName", SqlDbType.NVarChar);
//comm.Parameters.Add("@ContainerID", SqlDbType.NVarChar);
//comm.Parameters.Add("@ContainerStatus", SqlDbType.TinyInt);
//comm.Parameters.Add("@ContainerEID", SqlDbType.UniqueIdentifier,
16).Value = new Guid(this.EID);
//comm.Parameters.Add("@ContainerName", SqlDbType.NVarChar, 40).Value =
this.Name;
//comm.Parameters.Add("@ContainerID", SqlDbType.NVarChar, 40).Value =
this.ID;
//comm.Parameters.Add("@ContainerStatus", SqlDbType.TinyInt, 1).Value =
this.Status.ToString();
#endregion
comm.Parameters.AddWithValue("@ContainerEID", new Guid(this.EID));
comm.Parameters.AddWithValue("@ContainerName", this.Name);
comm.Parameters.AddWithValue("@ContainerID", this.ID);
comm.Parameters.AddWithValue("@ContainerStatus", this.Status.ToString());
comm.ExecuteNonQuery();
and the problem occurs when I execute the last line. The error returned
from SQL Server is as follows:
$exception {"Incorrect syntax near 'InsertContainerData'."} System.Exception
{System.Data.SqlClient.SqlException}
Using SQL Profiler, this is what it sees coming from my application:
exec sp_executesql N'InsertContainerData',N'@ContainerEID
uniqueidentifier,@ContainerName
nvarchar(6),@ContainerID nvarchar(4),@ContainerStatus
nvarchar(1)',@ContainerEID='42B1462A-ED4B-40B9-B627-75B364719731',@ContainerName=N'ct8888',@ContainerID=N'8888',@ContainerStatus=N'3'
What is going wrong with my application? Many thanks in advance.
Allen
figure out why I'm getting an error with each attempt.
The code I'm using is as follows:
SqlTransaction trans;
using (SqlConnection conn = new
SqlConnection(myConn)) //_connectionString))
{
conn.Open();
trans = conn.BeginTransaction();
SqlCommand comm = new SqlCommand("InsertContainerData", conn, trans);
#region unused
//comm.Parameters.Add("@ContainerEID", SqlDbType.UniqueIdentifier);
//comm.Parameters.Add("@ContainerName", SqlDbType.NVarChar);
//comm.Parameters.Add("@ContainerID", SqlDbType.NVarChar);
//comm.Parameters.Add("@ContainerStatus", SqlDbType.TinyInt);
//comm.Parameters.Add("@ContainerEID", SqlDbType.UniqueIdentifier,
16).Value = new Guid(this.EID);
//comm.Parameters.Add("@ContainerName", SqlDbType.NVarChar, 40).Value =
this.Name;
//comm.Parameters.Add("@ContainerID", SqlDbType.NVarChar, 40).Value =
this.ID;
//comm.Parameters.Add("@ContainerStatus", SqlDbType.TinyInt, 1).Value =
this.Status.ToString();
#endregion
comm.Parameters.AddWithValue("@ContainerEID", new Guid(this.EID));
comm.Parameters.AddWithValue("@ContainerName", this.Name);
comm.Parameters.AddWithValue("@ContainerID", this.ID);
comm.Parameters.AddWithValue("@ContainerStatus", this.Status.ToString());
comm.ExecuteNonQuery();
and the problem occurs when I execute the last line. The error returned
from SQL Server is as follows:
$exception {"Incorrect syntax near 'InsertContainerData'."} System.Exception
{System.Data.SqlClient.SqlException}
Using SQL Profiler, this is what it sees coming from my application:
exec sp_executesql N'InsertContainerData',N'@ContainerEID
uniqueidentifier,@ContainerName
nvarchar(6),@ContainerID nvarchar(4),@ContainerStatus
nvarchar(1)',@ContainerEID='42B1462A-ED4B-40B9-B627-75B364719731',@ContainerName=N'ct8888',@ContainerID=N'8888',@ContainerStatus=N'3'
What is going wrong with my application? Many thanks in advance.
Allen