Custom action (in C# dll):
[CustomAction]
public static ActionResult TestDbConnection(Session session)
{
using (var connection = new SqlConnection(session["CONNECTION_STRING"]))
{
try
{
connection.Open();
session["TEST_DB_CONNECTION_RESULT"] = "Connection succeeded.";
}
catch
{
session["TEST_DB_CONNECTION_RESULT"] = "Connection failed!";
}
return ActionResult.Success;
}
}
Popup that will display the test result message (in .wxs file):
<Fragment>
<UI>
<Dialog Id="TestDbConnectionResultDlg" Width="200" Height="80" Title="Testing DB Connection...">
<Control Id="OK" Type="PushButton" X="75" Y="50" Width="56" Height="17" Default="yes" Cancel="yes" Text="OK">
<Publish Event="EndDialog" Value="Return">1</Publish>
</Control>
<Control Id="Text" Type="Text" X="20" Y="12" Width="160" Height="40" Text="[TEST_DB_CONNECTION_RESULT]" />
</Dialog>
</UI>
</Fragment>
Button that will trigger sql connection test (in .wxs file):
<Control Id="TestDbConnection" Type="PushButton" X="20" Y="100" Height="16" Width="45" Text="Test">
<Publish Event="SpawnDialog" Value="TestDbConnectionResultDlg" Order="2">1</Publish>
<Publish Event="DoAction" Value="TestDbConnection" Order="1">1</Publish>
</Control>
Where should I initialize the CONNECTION_STRING? I have a InvalidOperationException, if I execute the code.
CONNECTION_STRING has not been initialized exception.
Thanks for the code!