sqlserver的自定义操作测试连接无法正常工作 [英] Custom Action for sqlserver Test connection not working
本文介绍了sqlserver的自定义操作测试连接无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好b $ b
检查sqlserver连接无法正确验证的自定义操作。测试连接按钮单击自定义操作如下。让我知道如何纠正它并使其正常工作
Hi
Custom action for checking sqlserver connection not validating correctly. Test connection button click custom action as below .Let me know how i can rectify it and make it working correctly
public static ActionResult TestSqlConnection(Session session)
{
try
{
if (session == null)
{
throw new ArgumentNullException("session");
}
SetSessionProperty(session, "DATABASE_TEST_CONNECTION", "0");
string sConnectionString = GetConnectionString(session, false);
if(string.IsNullOrEmpty(sConnectionString))
{
result = ActionResult.Failure;
}
else
{
using (SqlConnection sqlConect = new SqlConnection(sConnectionString))
{
sqlConect.Open();
SetSessionProperty(session, "DATABASE_TEST_CONNECTION", "1");
MessageBox.Show("Test Connection Successful", "Test connection", MessageBoxButtons.OK, MessageBoxIcon.Information);
result = ActionResult.Success;
}
}
}
catch (Exception ex)
{
InstallUtilities.WriteLogInstall(session, "exception occurs while connecting to database server", ex, true);
MessageBox.Show(ex.Message, "Test Coonection", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return result;
}
private static string GetConnectionString(Session session, bool isCustomActionData)
{
string sConnectionString=string.Empty;
if (GetSessionProperty(session, "DATABASE_SERVERNAME",isCustomActionData)=="0")
{
sConnectionString = string.Empty;
}
else
{
if((GetSessionProperty(session,"DATABASE_SERVERNAME",isCustomActionData)=="1"))
{
if ((GetSessionProperty(session, "DATABASE_WINDOWSAUTHENTICATION", isCustomActionData) == "1"))
{
sConnectionString = string.Format("Integrated Security=SSPI;Persist Security Info=False;Data Source={0};",
GetSessionProperty(session, "DATABASE_SERVERNAME", isCustomActionData).Trim());
}
else
{
sConnectionString = string.Format("Persist Security Info=False;Data Source={0};User ID={1};Password={2};",
GetSessionProperty(session, "DATABASE_SERVERNAME", isCustomActionData),
GetSessionProperty(session, "DATABASE_USERNAME", isCustomActionData),
GetSessionProperty(session, "DATABASE_PASSWORD", isCustomActionData));
}
}
}
return sConnectionString;
}
这是我的数据库设置对话框结构
this is my database setting Dialog structure
<Control Id="Test" Type="PushButton" X="25" Y="243" Width="100" Height="17" Text="!(loc.DatabaseServerDlg_Test)">
<Condition Action="disable"><![CDATA[DATABASE_WINDOWSAUTHENTICATION = "0" AND DATABASE_USERNAME = ""</Condition>
<Condition Action="enable"><![CDATA[DATABASE_WINDOWSAUTHENTICATION = "1" OR (DATABASE_WINDOWSAUTHENTICATION = "0" AND DATABASE_USERNAME <> "" AND DATABASE_PASSWORD <> "")</Condition>
<Publish Event="DoAction" Value="CA_DataBaseTestConnection" Order="1">1</Publish>
<Publish Property="DATABASE_VALID_LOGON" Value="1" Order="2"><![CDATA[DATABASE_TEST_CONNECTION = "1"</Publish>
<Publish Property="DATABASE_VALID_LOGON" Value="0" Order="2"><![CDATA[DATABASE_TEST_CONNECTION = "0"</Publish>
<Publish Property="ERROR_MESSAGE" Value="N" Order="3"><![CDATA[(DATABASE_TEST_CONNECTION = "1")</Publish>
<Publish Property="ERROR_MESSAGE" Value="!(loc.DatabaseServerDlg_AuthenticationErrorMessage)" Order="3"><![CDATA[DATABASE_TEST_CONNECTION = "0"</Publish>
<Publish Event="SpawnDialog" Value="GenericErrorDlg" Order="4"><![CDATA[DATABASE_TEST_CONNECTION = "0"</Publish>
</Control>
<Control Id="TestResult_Success" Type="Bitmap" X="250" Y="10" Width="24" Height="24" Text="BIN_SuccessBmp">
<Condition Action="hide"><![CDATA[DATABASE_VALID_LOGON <> 1</Condition>
<Condition Action="show"><![CDATA[DATABASE_VALID_LOGON = 1</Condition>
</Control>
<Control Id="TestResult_Failure" Type="Bitmap" X="250" Y="10" Width="24" Height="24" Text="BIN_ErrorBmp">
<Condition Action="hide"><![CDATA[DATABASE_VALID_LOGON = 1 </Condition>
<Condition Action="show"><![CDATA[DATABASE_VALID_LOGON <> 1</Condition>
</Control>
这是customAction.wxs中的惯例
this is customaction in customAction.wxs
<CustomAction Id="CA_DataBaseTestConnection" BinaryKey="BIN_CustomAction" DllEntry="TestSqlConnection" Execute="immediate" Impersonate="yes" Return="ignore" />
推荐答案
I已经找到了上述问题的解决方案。
I have figured out solution to above issue.
这篇关于sqlserver的自定义操作测试连接无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文