By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

Problem with prepared statements of DB2 using OLEDB

P: n/a
NS
Hi,

I am trying to execute a prepare statement using oledb provider for
DB2. The command.Prepare() statement is giving me an exception

" No error information available: DB_E_NOCOMMAND(0x80040E0C)."

My code is very simple and is working with other oledb provider, like
SQL Server and oracle.

The code is
OleDbConnection rConn = new
OleDbConnection("Provider=IBMDADB2.1;Persist Security Info=False;Data
Source=SAMPLE;Mode=ReadWrite;User id=db2admin;Password=db2admin;");
rConn.Open();
System.Data.OleDb.OleDbCommand command = new
System.Data.OleDb.OleDbCommand(null, rConn);

// Create and prepare an SQL statement.
command.CommandText = "insert into Department
(DEPTNO,DEPTNAME,MGRNO,ADMRDEPT,LOCATION) values (?,?,?,?,?)" ;

command.Parameters.Clear();
System.Data.OleDb.OleDbParameter pp = new
OleDbParameter("@tt",System.Data.OleDb.OleDbType.C har);
pp.Value = "A12";
command.Parameters.Add(pp);
System.Data.OleDb.OleDbParameter pp1 = new
OleDbParameter("@name",System.Data.OleDb.OleDbType .VarChar,29);
pp1.Value = "myFirstDept";
command.Parameters.Add(pp1);
System.Data.OleDb.OleDbParameter pp2 = new
OleDbParameter("@mgr",System.Data.OleDb.OleDbType. Char);
pp2.Value = "ABC";
command.Parameters.Add(pp2);
System.Data.OleDb.OleDbParameter pp3 = new
OleDbParameter("@adm",System.Data.OleDb.OleDbType. Char);
pp3.Value = "aa";
command.Parameters.Add(pp3);
System.Data.OleDb.OleDbParameter pp4 = new
OleDbParameter("@loc",System.Data.OleDb.OleDbType. Char);
pp4.Value ="San";
command.Parameters.Add(pp4);

command.ExecuteNonQuery();

rConn.Close();
I have tried all possible things that I can find on the internet.
Kindly let me know what am I missing...

Any help in this regard will be great.

Thanx,
NS

Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
NS
I missed a line....

command.Prepare();

before command.ExecuteNonQuery();

I even tried running the same code without Prepare(), but still the
same error.

I posted the message on .NET oledb forum and they replied that it might
be a problem with DB2 oledb provider.

Does any of u faced such a problem with prepared statements of DB2
oledb provider?

Nov 12 '05 #2

P: n/a
What version of DB2 are you using? The OLE DB driver was a catastrophe in
7.2, was better in 8.1, and is OK (even if not good) in 8.2. If you have DB2
7.2, I recommend you use the MS OLE DB over ODBC driver, with the DB2 ODBC
driver. With 8.x you should be OK.

"NS" <ne**********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I missed a line....

command.Prepare();

before command.ExecuteNonQuery();

I even tried running the same code without Prepare(), but still the
same error.

I posted the message on .NET oledb forum and they replied that it might
be a problem with DB2 oledb provider.

Does any of u faced such a problem with prepared statements of DB2
oledb provider?

Nov 12 '05 #3

P: n/a
NS
Thanx Mark for ur reply.

I am using DB2 version 8. But still getting the same problem with
prepared statements.

I am new to DB2, can u please tell me what is the connection string for
using MS OLE DB over ODBC driver, with the DB2 ODBC driver. Also do I
need to download something for it??

Thanx,
NS

Nov 12 '05 #4

P: n/a
You already have all the parts in MDAC and the DB2 client. The easiest way
to figure out a connection string is to create a DSN via the GUI, then read
what it does for you. Otherwise, it's all in the DB2 and MDAC documentation.

Personally, I would recommend against hard coding connection strings anyway,
especially as you can use AD to publish the whole connectivity issue. I'd
also go Kerberos, as hardcoding passwords in a connection string, as you
did, is asking for trouble.

"NS" <ne**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thanx Mark for ur reply.

I am using DB2 version 8. But still getting the same problem with
prepared statements.

I am new to DB2, can u please tell me what is the connection string for
using MS OLE DB over ODBC driver, with the DB2 ODBC driver. Also do I
need to download something for it??

Thanx,
NS

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.