473,395 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

C# and db2app.dll

Hi all,

I try to execute the "sqledrpd" - Api. I found it in the db2app.dll
renamed to sqledrpd_api, but my application crashes. Here's the
codesnippset.

Perhaps someone can help?!
Thanks in advance

Andy
[StructLayout(LayoutKind.Sequential)]
internal struct SQLCA
{
public string sqlcaid;
public long sqlcabc;
public long sqlcode;
public short sqlerrml;
public string sqlerrmc;
public string sqlerrp;
public long sqlerrd1;
public long sqlerrd2;
public long sqlerrd3;
public long sqlerrd4;
public long sqlerrd5;
public long sqlerrd6;
public string sqlwarn;
public string sqlstate;
}

[DllImport(@"db2App.dll", CharSet=CharSet.Auto)]
internal static extern int sqledrpd_api(string dbAlias, out SQLCA
sqlca);

and somewhere in my sourcecode:

public void DeleteDb(string dbName)
{
SQLCA sqlca = new SQLCA();
int ret = sqledrpd_api( dbName, out sqlca );
}
Nov 12 '05 #1
1 3075
I'll start of by stating this is not specific to DB2. You are expecting
certain things to just "work" when calling a C function that takes a
structure from a C# code -- this actually requires a LOT of work on the
C# side to do. Typically, the compiler knows that C# "string" maps to
"char*" or "char[]" in C, for instance, but it does not make this
distinction for structure types.

You cannot just pass in a .NET object to a C API that is expecting a
pointer to a structure as an output parameter. You probably want to
catalog your C function as taking an IntPtr instead of an SQLCA. This
would require you to use "unsafe" code so that you can get the address
of the structure you create and pass it in as (IntPtr)&mySqlca, for
instance.

The SQLCA structure is a fixed-sized structure -- 136 bytes. Your SQLCA
is full of variable-sized String objects; there's no way, for example,
for the C# compiler to "know" when it does the transition from C# to C
code that it needs to make sure sqlcaid is only 8 bytes long, for
example. For instance, for the SQLSTATE, the C# compiler will likely
try to interpret the sqlstate as a char* (4 bytes pointing to an area of
memory) instead of a char[5] (5 bytes inline to the structure).

Please read up on the .NET documentation of "unsafe" modes before you
proceed down this path. What I'd actually recommend that you if you
still want to do something like this is to write C wrappers to the APIs
that do the parsing of the SQLCA, and returns errors to the .NET code
based on what your parse out of it.

Andy Meyer wrote:
Hi all,

I try to execute the "sqledrpd" - Api. I found it in the db2app.dll
renamed to sqledrpd_api, but my application crashes. Here's the
codesnippset.

Perhaps someone can help?!
Thanks in advance

Andy
[StructLayout(LayoutKind.Sequential)]
internal struct SQLCA
{
public string sqlcaid;
public long sqlcabc;
public long sqlcode;
public short sqlerrml;
public string sqlerrmc;
public string sqlerrp;
public long sqlerrd1;
public long sqlerrd2;
public long sqlerrd3;
public long sqlerrd4;
public long sqlerrd5;
public long sqlerrd6;
public string sqlwarn;
public string sqlstate;
}

[DllImport(@"db2App.dll", CharSet=CharSet.Auto)]
internal static extern int sqledrpd_api(string dbAlias, out SQLCA
sqlca);

and somewhere in my sourcecode:

public void DeleteDb(string dbName)
{
SQLCA sqlca = new SQLCA();
int ret = sqledrpd_api( dbName, out sqlca );
}

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: StephenRichter | last post by:
I have installed the trial of db2 enterprise server on my w2k PC. Have also installed fix pack 8 of that product. I am using it to connect from an asp.net web page to an IBM as400. the 400 is...
6
by: Mauro Miotello | last post by:
I've to create a webapp with VS.Studio.NET 2003 and DB2 Enterprise. I've create a webform and put this code on PageLoad event: 1 Dim strConnection As String 2 strConnection =...
1
by: Mauro Miotello | last post by:
Someone are using successfully, VS.Studio 2003 on Windows 2003 with DB2 8.2.2 ? Mauro
1
by: Sanju | last post by:
Hi.. I have working on Windows XP Operating System.Installed J2sdk 1.4.07 and installed IBM DB2 UDB version 8.1 Then i got the following error.. The procedure entry point SQLPrepareW@12...
0
by: Steve Richter | last post by:
I am trying, really trying to use the DB2Connection class provided by IBM to connect to a database on my old reliable as400 from the asp.net web page. When I run the DB2Connection code in my...
4
by: alinehp | last post by:
Hi I have an access violation in DB2SYS.dll at each ending of my application. This is a multithreaded application. Threads are created and managed by Tomcat. One thread connects to DB2 base...
0
by: EyalS | last post by:
Hi, I have a process running on an XP machine, that uses the db2app.dll to get DB snapshots. When the DB is on another Windows machine, all is well. But when the DB is on an AIX machine,...
14
seraieis
by: seraieis | last post by:
Hi all, I've been working on a few home-grown apps for my department, one of which connects to a DB2 database and generates reports from it. It has worked splendidly on my machine, but this...
1
by: gimme_this_gimme_that | last post by:
Hello, Looking back on it - knowing what I know now - I should have run setup.exe by right clicking and explicitly running as an Administrator. Well, here I am. I installed DB2 Express-C from...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.