在sqlCon.open语句中出现错误;System.Data.SqlClient.SqlException';发

本文关键字:Data System SqlClient SqlException 错误 open sqlCon 语句 | 更新日期: 2023-09-27 18:00:11

public partial class Webpages_Default : System.Web.UI.Page
{
    SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        lblnorecordfound.Visible = false;
        gvRCATracker.Visible = false;
        if (!IsPostBack) {
            //Binding control
            sqlCon.Open();
            BindPriority();
            BindProductCategory();
            BindPortfolio();
            BindRCAResponseTeam();
            BindTSMReview();
            BindRCAStatus();
            sqlCon.Close();
            SetReadOnlyForDateControls();
        }               
    }
}

在sqlCon.open语句中出现错误;System.Data.SqlClient.SqlException';发

请确保如果您的Sql服务器作为默认实例运行,那么您需要在DataSource中使用".",例如

connectionString="Data Source=.;Initial Catalog=LMS;User ID=sa;Password=password"

否则,您需要指定服务器实例的名称。

connectionString="Data Source=.'INSTANCENAME;Initial Catalog=LMS;User ID=sa;Password=password"