user146043
user146043

Reputation:

Executing SQL against AS400 specifying *LIBL rather than a specific library

I have a requirement to perform basic SQL (an insert, in this case) against a file on the AS400. I'm writing a thick client, command line app in C# running on Windows 2008.

If I specify a library and a file as follows:

insert into somelibrary.somefile (col1,col2) values val1,val2

then it works. The problem is that the value of somelibrary will differ between users and environments. I'd like to use the library list *LIBL, so that it will pick up on whatever libraries that user has been allocated, in the correct order. I'd like to avoid having to use configuration files, if possible.

The user I'm testing with has, in his library list, the library which contains somefile. If I try:

insert into somefile (col1,col2...) values val1,val2

I get an error:

ERROR [42S02] [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0204 - somefile in username type *FILE not found.

I've tried adding *LIBL in the SQL, and also in the connection string, but it's not finding the file. I've tried quite a few combinations, as well as using slashes to separate the library and the file.

In case it's relevant the connection string is:

Driver={Client Access ODBC Driver (32-bit)}; System=" + server + "; UID=" + DBUser + "; PWD=" + DBPassword + ";";

Upvotes: 2

Views: 5096

Answers (1)

Buck Calabro
Buck Calabro

Reputation: 7648

The library list used for this request is the library list of the user profile used to authenticate against. The user profile points to two items that are interesting with respect to the library list: the Job Description and the Initial Program. Check the job description to see what the library list is. Probably, it won't have the library containing SOMEFILE. That leaves the initial program. If the library list is set in the initial program, you have a problem, because the initial program is only executed when the profile signs on to a terminal session.

The way around this is to create a user profile and job description that has the library list you need.

Upvotes: 1

Related Questions