Informix Client SDK and .Net connection question
Posted in 2003
Topics: Connectivity: ODBC / JDBC / .NET
Hello all, CSDK Driver: IBM Informix CSDK 9.52 2.81.TC3B2 For the IfxConnection.ConnectionString since you cannot use "DSN=XXX" as in the specs,how do you set up a connection string on production without hardcoding the uid and pwd information. Thanks Inadvance Chavan Koya
chavankoya189@hotmail.com (Chavan Koya) writes:
> CSDK Driver: IBM Informix CSDK 9.52 2.81.TC3B2
> For the IfxConnection.ConnectionString since you cannot use "DSN=XXX"
> as in the specs,how do you set up a connection string on production
> without hardcoding the uid and pwd information.
Don't hard code anything in your apps!!! For Java, I use a property
file and read it before setting up the database connection. Something
like this:
$ cat connect.properties
driver=com.informix.jdbc.IfxDriver
url=jdbc:informix-sqli://example.com:1526/foo
INFORMIXSERVER=fi_soctcp
#user=<username>
#password=<password>
$ cat foo.java
import java.sql.*;
import java.util.*;
public class foo {
public static void main(String[] args) {
Connection conn = null;
try {
ResourceBundle b = ResourceBundle.getBundle("connect");
String url = b.getString("url");
Properties p = new Properties();
Enumeration keys = b.getKeys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
String val = b.getString(key);
p.setProperty(key, val);
}
try { Class.forName(b.getString("driver")).newInstance(); }
catch (Exception e) { }
conn = DriverManager.getConnection(url, p);
// ...
}
catch (SQLException e) {
e.printStackTrace();
}
finally {
if (conn != null) {
try { conn.close(); }
catch (SQLException e) { }
}
}
}
}
I'd be surprised if you couldn't do something similar in .Net...
--
Forte International, P.O. Box 1412, Ridgecrest, CA 93556-1412
Ronald Cole <ronald@forte-intl.com> Phone: (760) 499-9142
President, CEO Fax: (760) 499-9152
My GPG fingerprint: C3AF 4BE9 BEA6 F1C2 B084 4A88 8851 E6C8 69E3 B00B