Odbc connection string format, not finding files

孤者浪人 提交于 2019-12-04 03:36:16

问题


This is kind of a 'double' question that might have a single answer.

I'm working with an Odbc Connection with an AS/400, with my connection string as follows:

driver={iSeries Access ODBC Driver}; system={0}; uid={1}; pwd={2}; DefaultLibraries=*USRLIBL;    

I'm able to connect to the system fine.

*USRLIBL contains all the necessary libraries from the user (which is of the type 'API only' which has access to all user libraries).

However, when I try to access certain ERP libraries, it says they can't be found, while other ones can.

So as an extremely basic walkthrough:

1. Open Connection - Query File 1 from Library A:  OK! - Close Connection
2. Open Connection - Query File 2 from Library A:  OK! - Close Connection
3. Open Connection - Query File 1 from Library B:  Exception  SQL0204 - in UserName type *FILE not found 

Ok, so I added in the specific library that the ERP files would be in, making the connection string as follows, just to test the program:

driver={iSeries Access ODBC Driver}; system={0}; uid={1}; pwd={2}; DefaultLibraries=*USRLIBL, LibraryB; 

But then I start getting a different problem (another extremely basic walkthrough)

1. Open Connection - Query File 1 from Library A:  OK! - Close Connection
2. Open Connection - Query File 2 from Library A:  OK! - Close Connection
3. Open Connection - Query File 1 from Library B:  OK! - Close Connection
4. Open Connection - Query File 1 from Library A again:  Exception SQL0202 - in LibraryB type *FILE not found.  

So my question(s) are:

Why doesn't the odbc connectionstring DefaultLibraries=*USRLIBL not return the correct libraries? (Note: I also tested this using an iDB2Connection which in fact works fine... however, the iDB2Connection can not be deployed as it literally crashes the server)

Why does the second walkthrough throw an exception, it just seems to 'skip past' *USRLIBL after reading from LibraryB even once.

Any thoughts?

Begin Edit:

There are actually two users, DEV and PROD

The *USRLIBL gets all the necessary Libraries from the Environment itself, so if when opening the connection, it detects a localhost environment, or anything that's unsecure (plus a few other caveats), it defaults to DEV log in credentials before creating the connection. This is why the system, uid, and pwd are designated as parameters in the connection (and not just stackoverflow I-dont-want-to-give-out-data placeholders)

The *USRLIBL then pulls the necessary libraries from the API user.

To Clarify, the way it's set up does work using the iDB2 Connector, but because of the limitations of our ERP system (we think), using it with an IIS 7 server causes a catastrophic failure, so we're working with the ODBC connector.

End Edit:


回答1:


You can qualify your table names as library.filename and not have to deal with any library list issues.

For more information:

Client Access ODBC: Default Libraries Setting

ODBC connection string keywords


Excerpts of the relevant parts are:

With SQL naming convention, the operating system does not perform a library list search to locate an unqualified object. If a default collection is defined, the default collection is used to resolve unqualified SQL statements.

...

With the SYS naming convention, the unqualified SQL statements go to the default collection. If there is no default collection, the current library is used. If no current library is specified, the library list is used.

...

Default Collection

A job attribute set by ODBC that determines the library used when processing SQL statements that contain unqualified SQL names. When a default collection is set all unqualified objects except procedures, functions and types must reside in the default collection, regardless of naming convention.

...

How can I get ODBC to search the library list?

As explained above, edit the ODBC data source and set system naming to SYS. The default library must be empty, or on versions older than R510, the default libraries setting must start with a comma so that no default collection is defined (for example, ",MYLIB1, MYLIB2").


Try this connection string to enable system naming and to not set a default library:

driver={iSeries Access ODBC Driver}; system={0}; uid={1}; pwd={2}; naming=1; DefaultLibraries=,*USRLIBL,LibraryB;




回答2:


If anyone runs into this post and is using the IBM.Data.DB2.iSeries .NET data provider as I am, the key point taken from above was using the naming=1 and not specifying a "Default Collection". I was finally successful when using the following portion in my connection string

LibraryList= MyLibrary1,MyLibrary2,MyLibrary3,MyLibrary4;naming=1;



回答3:


An alternative is to set up a separate user profile for each environment. Since the *USRLIBL is set by the job description, this would entail setting up a separate job description as well. For example:

user: WEB job desc: WEB library list: CUSTPROD, ITEMPROD, UTILITY

user: WEBTEST job desc: WEBTEST library list: CUSTTEST, ITEMTEST, UTILITY

The C# code does not change except for using the test or production user ID to authenticate.



来源:https://stackoverflow.com/questions/8172879/odbc-connection-string-format-not-finding-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!