0

我有一个正在使用 C# 的扫描仪加载项。

我的代码适用于模拟器,但不适用于扫描仪硬件本身。可能是因为扫描仪上没有 System.Data.SqlClient 吗?我不确定。有没有办法可以指定 System.Data.SqlClient 包含在我生成的 dll 文件中?

我得到的错误是 con.Open() 上的 Named Pipes Provider 错误 40。如果扫描仪没有库是一个问题,它不会在第一次引用 SqlConnection 时引发错误吗?源代码如下:

String clientName = "";

        try
        {
            // Setting up the SqlConnectionStringBuilder
            SqlConnectionStringBuilder buildIt = new SqlConnectionStringBuilder();
            buildIt.DataSource = "xxx.xx.x.xx";
            buildIt.InitialCatalog = "database";
            buildIt.IntegratedSecurity = true;

            using (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)
        {
            // Test code.
            // MessageBox.Show(err.Message);
            exporterHost.WriteSystemLog(LogType.Error, "E9999999", "SQL ERROR: " + err.Message);
            return false;
        }

谢谢!

4

0 回答 0