cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
PlinyElder
Level 7

Simple SQL Connection Test button

This is an Installscript project that i am working on and i am wanting a simple button that the user can click to test if there is an active SQL db at the location they point to. I already have a custom dialog created and working with my user input sql host address, user and password but im not seeing exactly what i should be using to do a test connection and show a messagebox with either a pass/fail message to the user.

I have been reading about SQLRTInitialize2 and SQLRTConnect2 but have been unsuccessful so far in getting a connection. Any help would be appreciated
Labels (1)
0 Kudos
(8) Replies
PlinyElder
Level 7

The function below is fired when the "Test" button is clicked by the user


function NUMBER SQL()
STRING sTest, svString;
NUMBER sDB;

begin
sTest = "MyDB";

//First initialize SQL Server runtime
SQLRTInitialize2();

sDB = SQLRTConnect2( "MyTest", "1.1.1.1", FALSE, "sa", "123456", sTest );

NumToStr(svString, sDB);
MessageBox( svString, WARNING );

end;


The messagebox returns '0' for the result.
0 Kudos
ch_eng
Level 7

PlinyElder,

0 means it was a success! If you compare your result "sDB" with the InstallShield constant "ISERR_SUCCESS", they should be the same.

HTH
0 Kudos
PlinyElder
Level 7

But its NOT actually a success. The result is returned immediately with '0' when i give the SQL IP address a bogus address. If i supply '0.0.0.0' as the ip address(which should always fail) and enter garbage db info, i always get the same '0' result returned.
0 Kudos
ch_eng
Level 7

PlinyElder,

To be honest, I don't have experience using SQLRTConnect2. When I had InstallScript MSI installers, I would instead use SQLRTTestConnection2 and that seemed to work as intended.

http://helpnet.installshield.com/installshield16helplib/mergedProjects/installshield16langref/SQLRTTestConnection2.htm

HTH
0 Kudos
PlinyElder
Level 7

Anyone else have any ideas? I think i can get SQLRTConnect2 to successfully connect, or ping the address, but i cant get any useful return codes back from it. Its telling me its a failed connection on good and bad ip addresses
0 Kudos
hidenori
Level 17

SQLRT* functions are designed to work in conjunction with the SQL Scripts view, and the SQLRTConnect function enables you test a connection specified in the ISSQLConnection table. If the connection does not exist, the function just returns 0 and does nothing. Make sure that you have the "MyTest" connection in your project.
0 Kudos
PlinyElder
Level 7

OK, i figured it out. It was actually pretty simply and i cant believe it took me this long to figure it out.

Using
SQLRTConnect( szConnection, szServer, bTrust, szUserName, szPassword );
will return expected result that i can return to the user.
0 Kudos