'instance failure' error while connection string is correct

后端 未结 7 446
醉梦人生
醉梦人生 2021-01-01 10:01

I have following code on page load event:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        con = New Sq         


        
相关标签:
7条回答
  • 2021-01-01 10:47

    I have connection:

    Data Source=MyComputerName\SQL2012ENTERPRS;Initial Catalog=RESTFUL; User Id=myuser; Password=mypass123;
    

    My server is : MyComputerName\SQL2012ENTERPRS

    But since I use string, I add more \ so, at my code It will be:

    public string connectionString = "Data Source=DAFWKN409C67Q\\SQL2012ENTERPRS;Initial Catalog=RESTFUL; User Id=rest_user; Password=rest_pwd_01;";
    

    I have forgoten that I must remove one of \ since I am not use default string block, I use XML file to save my connection string. Then everything is ok. So, my suggestion is your instance name is not correct.

    This is my connection string sample it I use local pc using SQL express:

    string servername = @"Data Source=.\SQLExpress;Initial Catalog=Workshop;Integrated Security=True";
    

    You should modify with your server name, and instance name by yourself, make sure it correct.

    0 讨论(0)
提交回复
热议问题