1

Im using this code for connect to db2 database - for testing purposes :

private void CTSS_connect(object sender, RoutedEventArgs e)
{
    iDB2Connection nc = new iDB2Connection();
    nc.ConnectionString = "DataSource=as400machine; DefaultCollection=myDatabase;";
    nc.Open();
    nc.Close();
}

The problem is that my program ask me only once for my UserID and password. When i debug program next time, it just login into machines without prompt for userID and Password. Should I add anything do the connectionString or there is something hidden in VisualStudio settings?

I'm using IBM iAccess for Windows and Personal Communicator for access AS400 machine so when I run the program I get popup windows from personal communicator where I have to enter my userID and Password

h00jraq
  • 85
  • 1
  • 8
  • Where are you asking for UserID and Password? Please provide that code as well. Since you're calling `.Close()`, you shouldn't be leaving the connection open, which would be my first guess. – krillgar Apr 14 '14 at 14:25
  • As I stated below I'm using IBM iAccess for Windows and Personal Communicator for access AS400 machine so when I run the program I get popup windows from personal communicator where I have to enter my userID and Password. – h00jraq Apr 14 '14 at 15:41

1 Answers1

0

My guess is that your Credentials are cached somehow. Most likely by your .NET-DB2-ADO.NET-Library.

This setting in Personal Communicator might help:

PC Settings


I Use following ConnectionString for DB2 Databases, it contains both Username AND password so the program does not have to ask the user:

DataSource=XXX;UserID=XXX;Password=XXX;CheckConnectionOnOpen=true;DataCompression=True;

Replace the "XXX" as follows:

AFAIK, DataSource can be a Hostname or an IPv4-Adress.
UserID: Your DB2-User
Password: Your Password


I recommend storing your connectionstrings in the app.config file like:

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="AS400_S"
         connectionString="DataSource=127.0.0.1;UserID=someDB2User;Password=someDB2Password;CheckConnectionOnOpen=true;DataCompression=True;" />
  </connectionStrings>
</configuration>

You can access it via C# code:

var appConfig = ConfigurationManager.OpenExeConfiguration("your.exe");
string connectionstring = appConfig.ConnectionStrings.ConnectionStrings["connstring1"].ConnectionString;

OR:

string connectionstring = ConfigurationManager.ConnectionStrings["connstring1"].ConnectionString;
M C
  • 626
  • 1
  • 11
  • 27
  • The problem is that probably few people will use the application so credentials can't be hardcoded. I don't user UserID and Password in my code because I'm using IBM iAccess for Windows so I when I first run this program I got an pop up from Personal Communicator to enter Login and Password but only first time. This work after computer reset but I don't know when it can be cached or how to prevent this caching. of course your solution with app.config is probably good solution but this is not safe and I'm not sure if this will survive security audit :). – h00jraq Apr 14 '14 at 15:40
  • @user2968396 as for your security audit: app.config files can be encrypted! I use following approach: http://stackoverflow.com/a/3350023/1469035 – M C Apr 15 '14 at 07:44
  • Ye but the problem is that I have like 10 differents id's for access as400 machines - the same for other users. This is why I want to ask user for login and pass each time when he click connect button. – h00jraq Apr 15 '14 at 07:47
  • @user2968396 there is something you may try, but i recommend you make a registry backup first: http://www.ehow.com/how_7541776_remove-iseries-password-cache.html I dont this Password Caching of Client Access aka iAccess for Windows myself. – M C Apr 15 '14 at 08:00
  • Hi, Thx for your help. Unfortunately this registry key(Client Access PW Cache) does not exist on my PC. I have no idea where those credentials can be stored. Stragne thing is that I have to always enter my id and passwd when I'm trying to connect as400 machine via personal communicator. – h00jraq Apr 15 '14 at 08:12
  • @user2968396 added screenshot of Personal Communicator setting that might be helpfull in your case. – M C Apr 15 '14 at 08:47
  • Hello! Problem is solved now. It seems like autoconnect function from communicator was the problem here. Even If I had chosen "Prompt Every Time", VS still was not asking me for password and login. Thx for help:) – h00jraq Apr 15 '14 at 09:32