private void BindDevelopRawMaterial()
{
string SQLCONNECTIONSTRING = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"].ToString();
SqlConnection myConnection = new SqlConnection(SQLCONNECTIONSTRING);
string cmdText = "select RawMaterialID,RawMaterial,Kind,Shaped,Amount,Unit,PertainToDepartment,Notes from [DevelopRawMaterial]";
SqlDataAdapter da = new SqlDataAdapter(cmdText, myConnection);
myConnection.Open();
DataSet ds = new DataSet();
da.Fill(ds);
GVDevelopRawmaterial.DataSource = ds;
myConnection.Close();
GVDevelopRawmaterial.AllowPaging = true;
GVDevelopRawmaterial.PageSize = 3;
GVDevelopRawmaterial.DataBind();
}webconfig code <appSettings>
<add key="SQLCONNECTIONSTRING" value="Data Source=40010909-6A8056;Initial Catalog=BH-ETHAN;User ID=sa;Password=admin;Integrated Security=True"/>
</appSettings>为什么在 调试的时候 能够 读取SQL信息
而远程访问 或 IIS 访问 就会 提示
无法打开登录所请求的数据库 "BH-ETHAN"。登录失败。
用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败。
{
string SQLCONNECTIONSTRING = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"].ToString();
SqlConnection myConnection = new SqlConnection(SQLCONNECTIONSTRING);
string cmdText = "select RawMaterialID,RawMaterial,Kind,Shaped,Amount,Unit,PertainToDepartment,Notes from [DevelopRawMaterial]";
SqlDataAdapter da = new SqlDataAdapter(cmdText, myConnection);
myConnection.Open();
DataSet ds = new DataSet();
da.Fill(ds);
GVDevelopRawmaterial.DataSource = ds;
myConnection.Close();
GVDevelopRawmaterial.AllowPaging = true;
GVDevelopRawmaterial.PageSize = 3;
GVDevelopRawmaterial.DataBind();
}webconfig code <appSettings>
<add key="SQLCONNECTIONSTRING" value="Data Source=40010909-6A8056;Initial Catalog=BH-ETHAN;User ID=sa;Password=admin;Integrated Security=True"/>
</appSettings>为什么在 调试的时候 能够 读取SQL信息
而远程访问 或 IIS 访问 就会 提示
无法打开登录所请求的数据库 "BH-ETHAN"。登录失败。
用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败。
如果你远程访问,连接字符串肯定就要写服务器上Sql的实例
<add key="SQLCONNECTIONSTRING" value="server=40010909-6A8056;database=BH-ETHAN;User Id=sa;pwd=admin"/>
直接删除 Integrated Security=True" 就可以了
即可