在我的代碼中,兩個表已連接並且在本地Host中正常工作。但是,當我連接相同的代碼時,代碼不是加工。服務器主體「」無法在當前安全上下文中訪問數據庫
連接字符串:
string constr = ConfigurationManager.ConnectionStrings["strconstr"].ConnectionString;
string constr = ConfigurationManager.ConnectionStrings["constrHOS"].ConnectionString;
private void BindContactPerson(string hdnHospitalContactPersonID)
{
BD_Hospital iHospital = new BD_Hospital();
string constr = ConfigurationManager.ConnectionStrings["constrHOS"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT D.DepartmentName,DS.DesignationName,hc.ContactPersonName,hc.ContactPersonAddress,hc.Mobile,hc.Phone,hc.AadhaarCardNo FROM HospitalContactPersonDeatils hc LEFT JOIN VAN_SETTING.[dbo].[Department] D ON D.DepartmentID =hc.DepartmentID LEFT JOIN VAN_SETTING.[dbo].[Designation] DS ON DS.DesignationID =hc.DesignationID where HospitalID='" + hdnHospitalContactPersonID + "' ", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
gvCustomers.DataSource = dt;
gvCustomers.DataBind();
}
}
}
}
誤差圖像:
如何連接兩個數據庫,並使用的SqlConnection CON C# –