函数在扫描器模拟器上运行,而不是扫描器本身(c#, SQL)

本文关键字:扫描器 SQL 模拟器 运行 函数 | 更新日期: 2023-09-27 18:14:33

我正在开发一个扫描仪的加载项。我在写一个特定的函数时遇到了问题。问题似乎是与我的连接字符串。代码在扫描器模拟器上运行良好,但在扫描器本身上不能运行。知道是怎么回事吗?

我得到错误在建立与服务器的连接时发生错误。在连接SQL Server 2005时,出现此问题可能是由于……(提供程序:Named Pipes提供程序,错误- 40无法打开到SQL Server的连接)

扫描器使用活动目录,我想。这可能就是问题所在。

代码如下:

    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

函数在扫描器模拟器上运行,而不是扫描器本身(c#, SQL)

由于某种原因,我们正在使用的系统在不同的端口上处理SQL连接。这就是问题所在

仍然好奇它在模拟器上工作,而不是硬件。