Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to IBM DB2 using their .Net Provider

Status
Not open for further replies.

Lladro

Programmer
Mar 5, 2007
18
US
Good Afternoon All!

I have a web application that connects to an IBM database. Occasionally, I get this error:

at IBM.Data.DB2.iSeries.iDB2Exception.throwDcException(MpDcErrorInfo mpEI, MPConnection conn) at
IBM.Data.DB2.iSeries.iDB2Command.reportDCError(Int32 rc) at
IBM.Data.DB2.iSeries.iDB2Command.Prepare() at IBM.Data.DB2.iSeries.iDB2Command.ExecuteReader(CommandBehavior behavior) at IBM.Data.DB2.iSeries.iDB2Command.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) at title1.LoginCredentials() A communication error occurred.

Has anyone ever run into this problem? If so, how did you rectify the situation?

Any help would be GREATLY appreciated.
 
one other thought. make sure you dispose of your connection objects once your finished with them. example:
Code:
OleDbConnection cnn = new OleDbConnection("...");
try
{
   cnn.open();
   //do work. commit if transaction in progress
}
catch
{
   //rollback if transaction in progress
}
finally
{
   cnn.close();
   cnn.dispose();
}
another shortcut is the using statement
Code:
using(OleDbConnection cnn = new OleDbConnection("..."))
{
   try
   {
      cnn.open();
      //do work...
   }
   catch
   {
      //rollback/log error
   }
}
this will automatically close and dipose of the connection object once it leaves the using brackets

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
are you using v5r3 or v5r4 version of client access? The newer version has some enhancements dealing with communications. As mentioned by Jason, make sure you are closing connections and disposing properly. I would also highly recommend setting a connection pool up in the connection string.
 
Code:
Dim ConnStr400 As iDB2Connection = New iDB2Connection(DataSource=ur.iseries.com;UserID=USR;Password=PWD;MaximumPoolSize=10;)

ConnStr400.Open()

Dim cmd1 As iDB2Command = New iDB2Command(library.sproc, ConnStr400)

        Try
        	        	cmd1.CommandType = CommandType.StoredProcedure
        	cmd1.Parameters.Add("mykey", iDB2DbType.iDB2VarChar, 10)
       		cmd1.Parameters("mykey").Direction = ParameterDirection.Input
        	cmd1.Parameters("mykey").Value = "53179"
		Dim drReader400 As iDB2DataReader = cmd1.ExecuteReader
		While drReader400.Read
			'do stuff
		End While
		
        Catch ex As Exception
        	'do error handling stuff
        Finally
            cmd1.Dispose
            ConnStr400.Close()
        End Try

here is code that works for me if it helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top