我正在为扫描仪开发一个插件。我遇到了我正在编写的特定功能的问题。问题似乎与我的连接字符串有关。该代码在扫描仪模拟器上运行良好,但在扫描仪本身上却不行。任何想法可能会发生什么?
我收到错误建立与服务器的连接时发生错误。连接到 SQL Server 2005 时,此故障可能是由于...(提供程序:命名管道提供程序,错误 - 40 无法打开与 SQL Server 的连接)
我认为扫描仪使用 Active Directory。这可能是问题所在。
代码如下:
private bool confirmName(String clientID)
{
String clientName = "";
try
{
// Setting up the SqlConnectionStringBuilder
SqlConnectionStringBuilder buildIt = new SqlConnectionStringBuilder();
buildIt.DataSource = "xxx.xx.x.xx";
buildIt.InitialCatalog = "Test_Clinical";
buildIt.IntegratedSecurity = true;
SqlConnection con = new SqlConnection(buildIt.ConnectionString);
con.Open();
using (SqlCommand command = new SqlCommand("SELECT First_Name, Last_Name FROM background WHERE Patient_No=@Patient_No", con))
{
command.Parameters.AddWithValue("@Patient_No", clientID);
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
clientName = reader.GetString(0).Trim() + " " + reader.GetString(1).Trim();
} // end if (reader.hasRows)
else
{
// No client found for this ID.
return false;
} // end else
} // end using (SqlCommand command = new SqlCommand("SELECT First_Name, Last_Name FROM background WHERE Patient_No=@Patient_No", con))
} // end try
catch (Exception err)
{
//MessageBox.Show(err.Message);
exporterHost.WriteSystemLog(LogType.Error, "E9999999", "SQL ERROR: " + err.Message);
return false;
}
// At this point, we should have a valid client name.
// Creating a Dialog and giving it the appropriate text.
SampleDialog checkIt = new SampleDialog();
checkIt.setQuestion("Do you want to scan a document for " + clientName + "?");
if (checkIt.ShowDialog() == DialogResult.OK)
{
return true;
} // end if (checkIt.ShowDialog() == DialogResult.OK)
else
{
return false;
} // end else
} // end confirmName