I'm trying to establish connection to database through scripting and it's the first time I'm doing this. I was able to create the following script but it seems that there's a bug that everytime there's unsuccessful connection, there's a default "JMP Alert" pop-up (see snapshot) instead of being contained within the "Try" function (I was trying with an incorrect database name of "TEST" which led to the pop-up. Is there a way to control this ?
Additionally, are there any good reading material (e.g. basic best practice) for incorporating SQL to JMP script ?
Many Thanks!
names default to here(1);
//Standard SQL syntax string to create database connection from JMP
DB.SQL = "DSN="||"DSN_Name" ||";Description=" || "DSN_Desc" || ";
Trusted_Connection=Yes;APP=JMP;DATABASE="|| "DB_Name" || ";";
//Expression to arrange the User Interface of PODS setup
//Require users to input Database Source Name (DSN Name), Database Source Description (DSN Description) and Database Name
DB_Connection.UI = expr(
Hlistbox(spacerbox(size(5,5)),
Vlistbox(align("right"),spacerbox(size(5,5)),
vb1_1 = vlistbox(align("left"),
panelbox("Insert PODS Connection Info",
lineupbox(ncol(2),
Textbox("DSN Name : "),TEB_DSN_Name = Texteditbox("",set width(150)),
Textbox("DSN Description : "),TEB_DSN_Desc = Texteditbox("",set width(150)),
Textbox("Database Name : "),TEB_DB_Name = Texteditbox("",set width(150))
)
),
spacerbox(size(5,5)),
temp1_1 = Textbox("PODS Connection Status: ")
),
spacerbox(size(3,3)),
Test_DB_Connection.button,
spacerbox(size(3,3)),
button box(" Cancel ",currentwindow()<<close window)
)
)
);
//Expression to set up "Set Connection" button
//Takes input values, substitute Standard SQL syntax DB.SQL with input values and execute open connection command
//Flag out "Successful" or "Unsuccessful" as results
Test_DB_Connection.button = expr(
button box(" Set Connection ",
Input.DSN_Name = TEB_DSN_Name << Get Text();
Input.DSN_Desc = TEB_DSN_Desc << Get Text();
Input.DB_Name = TEB_DB_Name << Get Text();
DB.SQL_Updated = Substitute(DB.SQL,"DSN_Name",Input.DSN_Name,"DSN_Desc",Input.DSN_Desc,"DB_Name",Input.DB_Name);
try(db = Create database connection (DB.SQL_Updated),
print("Unable to connect to Database")
);
try(db << get type;
try(temp1_1 << delete);
temp1_1 = hlistbox(
Textbox("PODS Connection Status: "),
Textbox("Successful", << font color(4))
);
vb1_1 << append (temp1_1);
,
try(temp1_1 << delete);
temp1_1 = hlistbox(
Textbox("PODS Connection Status: "),
Textbox("Unsuccessful", << font color(3))
);
vb1_1 << append (temp1_1);
,
);
)
);
nw1 = new window("PODS Connection Setup",
showtoolbars(0), showmenu(0),
DB_Connection.UI;
);