cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
alon2580
Level 5

Custom code eception causes error in installation

Hi,
during installation I'm executing a custom code that suppose to check connection to a DB.
if the connection isn't created the code throws an exception that I'm catching and showing to the user-in order that he will fix the parameters he entered.
After he fixes the parameters the installation countinus.
My problem is that because of that the IA thinks there was an error in the code and in the install complete panel acts as is there were errors.
the questions is: is there a way to tell IA to ignore exception from that specific action,or do something else that even if there were exception in my custom rule- IA won't treat it as an error?

10x
Labels (1)
0 Kudos

(10) Replies
qqqqqq
Level 7

alon2580 wrote:
Hi,
during installation I'm executing a custom code that suppose to check connection to a DB.
if the connection isn't created the code throws an exception that I'm catching and showing to the user-in order that he will fix the parameters he entered.
After he fixes the parameters the installation countinus.
My problem is that because of that the IA thinks there was an error in the code and in the install complete panel acts as is there were errors.
the questions is: is there a way to tell IA to ignore exception from that specific action,or do something else that even if there were exception in my custom rule- IA won't treat it as an error?

10x

I am doing almost the same thing....
1.But .. are you asking the user to re-enter the parameters in the INSTALL phase? If yes, you need a panel to get the input from user.. you can't have custom panel in INSTALL phase. So my question is how do you get the new parameters from the user?
0 Kudos
alon2580
Level 5

I'm sorry,I didn't explain my self.
I'm using the advanced user input panel and than parsing the input in my custom code.
if I "decide" that the input is wrong I'm using the show message dialog action to notify the user and give him 2 options:1)go back to the advanced user input to correct what he entered.2)Ignore and continue.
if he decide to go back so he needs to fix his input and than the custom code checks his input again and so on.
0 Kudos
purcellk24
Level 7

In your custom code, don't throw an InstallerException. The moment you do, you tell the installer that there was a problem and it won't be "successful" Instead, catch your SQL Exception and set an IA variable. Then you can compare your IA variable to see if it was successful or not.
0 Kudos
alon2580
Level 5

thanks for the reply I will try that and post the result
0 Kudos
alon2580
Level 5

so I tried-in did in the first place my class had the "throws InstallException" in its declaration,so I removed it and instead used try and catch for SQLExceptions,but still if SQLException is thrown and catched by the code the installer reports it as an error...
any other idea?

p.s I', posting my code if it's help.

public class DBconnectionTest extends CustomCodeAction
{
public void install( InstallerProxy ip )
{
DB db = new DB();
String messageToDisplay=new String();
String restartNeeded=new String("NO");
//setting the flag for presenting a user to the message to NO-will be chnage in the case of need
Object previousValue=ip.setVariable("MESSAGE_TO_DISPLAY","NO");
//getting the user input.
String host = ip.substitute("$USER_HOST$") ;
String port = ip.substitute("$USER_PORT$") ;
String userName = ip.substitute("$USERNAME_TABLES$") ;
String password = ip.substitute("$PASSWORD_TABLES$") ;
String databaseName = ip.substitute("$DATABASE_NAME$");
Connection conn=db.dbConnect("jdbc:jtds:sqlserver://"+host+":"+port,userName,password);
db.setDatabaseName(databaseName);
if(conn!=null) //meaning there is a connection
{
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}

conn=db.dbConnect("jdbc:jtds:sqlserver://"+host+":"+port+"/"+databaseName,userName,password);
if(conn!=null)
{
Long dbVersion=new Long(-1);//for intialization
try {
if((dbVersion=db.checkVersion(conn))!=0)
{
String dataBaseVersion = ip.substitute("$DBVERSION$") ;
Long serverVersion=new Long(dataBaseVersion);
if(!db.compareVersion(dbVersion,serverVersion))
{

messageToDisplay = messageToDisplay.concat("The version of the server and the version of the database do not match."
+"\nPlease delete the existing database and rerun the installer");
restartNeeded="YES";
}
}
else
{

if(!db.createTables(conn))
{

messageToDisplay = messageToDisplay.concat("The connection to DB server succeeded, but creation of a table in "+databaseName+" database failed:\n");
messageToDisplay = messageToDisplay.concat(db.getMessge());
messageToDisplay = messageToDisplay.concat("\nPlease check that the user has sufficient permissions and that the server allows to create a table");
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
else
{

conn=db.dbConnect("jdbc:jtds:sqlserver://"+host+":"+port,userName,password);
try {
if(!db.createDB(conn))
{

messageToDisplay = messageToDisplay.concat("The connection to DB server succeeded, but creation of "+databaseName+" database failed:\n");
messageToDisplay = messageToDisplay.concat(db.getMessge());
messageToDisplay = messageToDisplay.concat("\nPlease check that the user has sufficient permissions and that the server allows to create "+databaseName+" database");

}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
else
{ //meaning there is no connection-checking if this its worng credentials or DB not exist

messageToDisplay = messageToDisplay.concat("Can't connect to the database server: \n");
messageToDisplay = messageToDisplay.concat(db.getMessge());
messageToDisplay = messageToDisplay.concat("\nPlease check and correct the connection parameters");

}

if(messageToDisplay.length()!=0)
{
Object previousValue2=ip.setVariable("MESSAGE_TO_DISPLAY",messageToDisplay);
Object previousValue3=ip.setVariable("RESTART_NEEDED",restartNeeded);
}
}

0 Kudos
qqqqqq
Level 7

alon2580 wrote:
I'm sorry,I didn't explain my self.
I'm using the advanced user input panel and than parsing the input in my custom code.
if I "decide" that the input is wrong I'm using the show message dialog action to notify the user and give him 2 options:1)go back to the advanced user input to correct what he entered.2)Ignore and continue.
if he decide to go back so he needs to fix his input and than the custom code checks his input again and so on.


So you do this in PRE-INSTALL step .. and as user inputs parameter you try to make connection to the database ... rite?

yes .. using IA variable would better idea than .. throwing a exception
0 Kudos
qqqqqq
Level 7

In your code..
do not change the declaration ... let it be install(... ) throws InstallException

When you catch the sqlException .. set $some_variable$= false

then show the message dialog if the variable is "false" and go back to the previous panel
0 Kudos
alon2580
Level 5

if I understand what you suggested right-that is exactly what I do.
at the beginning of the code you can see:
Object previousValue=ip.setVariable("MESSAGE_TO_DISPLAY","NO");
now-if I catch an sqlEception I writing its cause(I'm doing that in another class-DB, which I didn't post here)to a string and than concating that string to the message I want to dislplay to the user: "messageToDisplay = messageToDisplay.concat...." and than at the end of the code I'm checking the length of messageToDisplay and it's not null I'm changing the variable "MESSAGE_TO_DISPLAY" that I set to "NO" at the beginning to the new value.
all that I'm doing in the code-IA checks the value of "MESSAGE_TO_DISPLAY" and if it differs from "NO" it prompts the user with a message panel.

that is what you meant right? if so-it doesn't work :mad:
0 Kudos
qqqqqq
Level 7

the function should be

public void install( InstallerProxy ip ) throws InstallException
{
// your code
}

Did you check the debug output if there is any exception?
there must be some error in installation log also.
0 Kudos
alon2580
Level 5

I did what you suggested and I found out what was the problem.
in my code I have this line
String dataBaseVersion = ip.substitute("$DBVERSION$")
to get the value of DBVERSION variable-the problem is that in my development machine this value is not set to a reasonable value-only during a build a replace this value with a real one-hence it has a problem retrieving this value and that was the exception.

Thank you very fro your help!
0 Kudos