DB2DataAdapter.Fill(dataset) throws error "SQL0901N (Reason "CPF4273".) SQLSTATE=58004" - db2

My application is Dot Net based.I am using VS My application uses IBm DB2 at its backend.
My Query is
SELECT A, B FROM SERVER.D WHERE A IN
(SELECT C FROM SERVER.E WHERE X = '01OBPP' AND Y= 'U' AND Z= '1')
A,B,C,X,Y,Z-COLUMN NAME, SERVER- SERVER NAME, D AND E -TABLE NAME
PFB the code-
DB2DataAdapter dbAdapter = null;
DB2Connection dbConn = null;
DB2Command dbCommand;
DataSet dsReturnDataSet ;
dbConn = new DB2Connection(connectionString);
if (dbConn.State == ConnectionState.Closed) dbConn.Open();
dsReturnDataSet.Clear();
dbCommand = GetCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConn;
dbAdapter = new DB2DataAdapter((DB2Command)dbCommand);
dbAdapter.Fill(dsReturnDataSet);
return dsReturnDataSet;
The GetCommand() method has the following statement
DB2Command dbCommand;
dbCommand = null;
dbCommand = new DB2Command();
dbCommand.CommandType = CommandType.Text;
dbCommand.CommandTimeout = 30;
return dbCommand;
While it hits the line 'dbAdapter.Fill(dsReturnDataSet);' it stucks there for a very long time and after that it throws the error
"ERROR [58004] [IBM][AS] SQL0901N The SQL statement failed because of
a non-severe system error. Subsequent SQL statements can be processed.
(Reason "CPF4273".) SQLSTATE=58004"
Please provide some pointers.
i will be very grateful if any one can give some pointers as to hoW to solve this error.

Check your database log. There should be a db2diag.log file in the db2dump directory under the instance's sqllib directory. Search this file for the above error and it should contain the root cause (that non-severe system error) that it refers to.

Related

Dblink is not working in java

String id="";
List list = null;
Query query = null;
Session session = getSession();
String sql = "select id from student#dblink s, location#dblink l where s.id in (select name from Employ where id='" +Id +"') and s.country_id = l.country_id and l.country_end = '"+countryEnd+"'";
query = session.createSQLQuery(sql);
System.out.println("sql.1."+sql);
list = query.list();
if(list.size()>0)
id = list.get(0).toString();
else
id= "0";
System.out.println("Stage2Ubr Id is:"+id);
return id;
Here I got exception like "org.hibernate.exception.GenericJDBCException: could not execute query". Sometimes this exception is not coming. Sometimes it's working fine without exception. This exception won't come if dblink is working fine.Please help me. How to check wheather the dblink is working fine or not?

Logfile Class error "You cannot execute this operation since the object has not been created."

We wanted to automate few management operations for new SQL Server installation, so we started looking into
LogFile Class
But this class doesn't let us run the ALTER() method to change log file location. Also doesn't let us add a new file and drop and existing file. Anyone know the internals of this class :) ?
NOTE: I know we can run a SQL query and run ALTER DATABASE MODIFY FILE and copy files and restart db. This question is specific to this class.
I also tried to alter an existing file instead of creating a new one and dropping existing one , and it throws the same error.
ERROR
"{"Drop failed for LogFile 'DBAUtility_log'. "}"
{"You cannot execute this operation since the object has not been created."}
class Program
{
static void Main(string[] args)
{
Server srv = new Server("xx");
Database db = default(Database);
db = srv.Databases["DBAUtility"];
//LogFile LF = new LogFile(srv.Databases.ItemById(0),'DBAUtility_log');
//Console.WriteLine("DB:", srv.Databases.Count());
Console.WriteLine(srv.Name);
Console.WriteLine("DBName" + srv.Databases.ItemById(5).ToString());
LogFile lf = new LogFile();
Console.WriteLine("LF:" + lf.ToString());
lf.Parent = db;
lf.Name = "DBAUtility_NEWLOG";
lf.FileName = "M:\\DBFiles\\SQLlog\\1\\DBAUtility_1.ldf";
lf.Create();
LogFile lf2 = new LogFile();
lf2.Parent = db;
lf2.Name = "DBAUtility_log";
lf2.FileName = "C:\\Install\\DBAUtility_1.ldf";
lf2.Drop(); //ERROR HERE
}
}
Create a log file for this database
$LogFileName = $db.name + '_Log'
$LogFile = New-Object ('Microsoft.SqlServer.Management.SMO.LogFile') ($db, $LogFileName)
$db.LogFiles.Add($LogFile)
$LogFile.FileName = $LogFileName + '.ldf'
$LogFile.Size = $logfilesize * 1024
$LogFile.GrowthType = 'KB'
$LogFile.Growth = $logfilegrowth * 1024
$LogFile.MaxSize = -1
$db.Create()

PostgreSQL, Get database exists with Npgsql

I cant get reliable checking for database existence in NET/Npgsql at my program startup.
Here is code:
Public Function dbExists(ByVal _dbName As String) As Boolean
Dim retval As Boolean = False
Using mCon As New NpgsqlConnection(String.Format( _
"Server={0};Port={1};User Id={2};Password={3};", _
dbserver, dbport, "postgres", dbpass))
Try
mCon.Open()
Using nCom = New NpgsqlCommand("SELECT 1 FROM pg_database WHERE datname='" + _dbName + "'", mCon)
retval = CBool(nCom.ExecuteScalar())
End Using
Catch ex As Exception
retval = False
End Try
End Using
Return retval
End Function
This function return True no matter database exists or not.
I also try with null checking on ExecuteScalar, getting Count(*) and all what I can without better result.
What to do to get it working?
Null checking on 'ExecuteScalar()' works for me (PostgreSQL 9.3 and Npgsql 2.0.12).
Are you checking 'ExecuteScalar() == null'?
ExecuteScalar will return a .NET null not DBNull.Value (since it is not a record with a null value, it signifies no matching result).
I'm not a VB person but here's how I achieved it in C#:
bool dbExists;
using (NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=testpass"))
{
conn.Open();
string cmdText = "SELECT 1 FROM pg_database WHERE datname='temp'";
using (NpgsqlCommand cmd = new NpgsqlCommand(cmdText, conn))
{
dbExists = cmd.ExecuteScalar() != null;
}
}

Using DB2, "statement.executeQuery()" throws SqlEception only in my system

//Class UserProfileDBUtil.java
Connection conn = null;
PreparedStatement statment = null;
ResultSet rs = null;
try{
String sqlString = "select count(*) from "+AGENCY_SCHEMA_NAME+".AGENCY WHERE AGENCYCODE= ? and ENABLEDFLAG = ?";
conn = JDBCUtils.getConnection(JDBCUtils.WP_ODS);
statment = conn.prepareStatement(sqlString);
statment.setString(1, agencyCode.toUpperCase());
statment.setString(2, "Y");
rs =statment.executeQuery(); // SQL Error Line 42
while(rs.next())
{
if(rs.getInt(1) > 0 )
{
return true;
}
}
log.error("Agency for agency code "+agencyCode+" is not available or not active");
}
LOG :
com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -401, SQLSTATE: 42818, SQLERRMC: =
at com.ibm.db2.jcc.b.sf.e(sf.java:1680)
at com.ibm.db2.jcc.b.sf.a(sf.java:1239)
at com.ibm.db2.jcc.c.jb.h(jb.java:139)
at com.ibm.db2.jcc.c.jb.a(jb.java:43)
at com.ibm.db2.jcc.c.w.a(w.java:30)
at com.ibm.db2.jcc.c.cc.g(cc.java:161)
at com.ibm.db2.jcc.b.sf.n(sf.java:1219)
at com.ibm.db2.jcc.b.tf.gb(tf.java:1818)
at com.ibm.db2.jcc.b.tf.d(tf.java:2294)
at com.ibm.db2.jcc.b.tf.X(tf.java:508)
at com.ibm.db2.jcc.b.tf.executeQuery(tf.java:491)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeQuery(WSJdbcPreparedStatement.java:559)
at UserProfileDBUtil.isAgencyActive(UserProfileDBUtil.java:42)
The error you're getting is a -401, which means:
The data types of the operands for the operation operator are not
compatible or comparable.
I would check and make sure that the parameters you're passing in are using the right data types. If you catch the exception, you should be able to use the exceptions Message property to see what the operator is. See here for an example.

Batching in ADO.NET without DataAdapters

Is it possible to implement batching of multiple stored procedure calls (doing updates/deletes) in ADO.NET without resorting to DataAdapters?
You could try using System.Data.SqlClient.SqlCommandSet. It's actually internal, but Ayende made a wrapper to make it public.
Code is currently hosted in sourceforge.
You're SQL text can contain multiple commands. If you return multiple result sets, then you can use a DataReader and use the NextResult function. What I often do is store the SQL to execute as an Embedded Resource, then load that text. If it contains parameters, then set the parameters just like you would normally.
For example, I have a file:
UPDATE dbo.QuotePricedLineItem
SET fkQuoteVendorLineSet = NULL
FROM dbo.QuotePricedLineItem qpli
INNER JOIN dbo.QuoteLineItem qli ON qpli.Id = qli.Id
WHERE qli.fkQuote = #quoteId AND qpli.fkQuoteVendorLineSet = #ciscoConfigId
DELETE CiscoQuoteLineItem
FROM CiscoQuoteLineItem cqli
INNER JOIN QuoteLineItem qli ON cqli.Id = qli.Id
WHERE qli.fkQuote = #quoteId AND cqli.fkCiscoQuoteVendorLineSet = #ciscoConfigId
that I execute as such:
using (SqlConnection conn = DbUtils.CreateConnection() as SqlConnection)
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = MvcApplication.GetResource("SQL.DemoteCiscoQuoteLineItems.sql");
cmd.Parameters.AddWithValue("#quoteId", q.Id);
cmd.Parameters.AddWithValue("#ciscoConfigId", configSetId);
cmd.ExecuteNonQuery();
}
Note that MvcApplication.GetResource is not a built in function - it's one you have to write... here's mine:
public static string GetResource(string p)
{
Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("CortexQuoting.Res." + p);
if (s == null) return null;
StreamReader sw = new StreamReader(s);
string ss = sw.ReadToEnd();
sw.Close();
return ss;
}