SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified for MDF file

后端 未结 2 1411
逝去的感伤
逝去的感伤 2021-01-24 17:49

I have added a database file (.mdf) to my application using Visual Studio built-in functionality. Database is in the App_Data folder. It is running fin

相关标签:
2条回答
  • 2021-01-24 18:11

    The fix for me was making sure I had the correct project set for startup in the solution. Right click project and "Set as Startup Project"

    0 讨论(0)
  • 2021-01-24 18:16

    The whole User Instance and AttachDbFileName= approach is flawed - at best! Also, it's only supported by the Express edition of SQL Server - so if your hoster has anything other than Expres, you're basically screwed.

    The real solution in my opinion would be to

    1. install SQL Server Management Studio Express

    2. create your database in SSMS Express, give it a logical name (e.g. MyDatabase)

    3. connect to it using its logical database name (given when you create it on the server) - and don't mess around with physical database files and user instances. In that case, your connection string would be something like:

      Data Source=.\\SQLEXPRESS;Database=MyDatabase;Integrated Security=True
      

      and everything else is exactly the same as before...

    Now, when you go and upload your web site to the hosting site, you need to get the necessary SQL scripts to create and populate your database on the hosting site - you can do this by using Tasks > Generate Scripts from the SSMS Express tool, or by some other means.

    Then, on the hosting site, you need to execute those SQL scripts to create and populate your database (and later on: execute the change scripts to keep the database up to date).

    Your connection string will also most likely change to something like:

    Server=(ip-address-or-name);Database=MyDatabase;User ID=YourUserIdHere;Pwd=YourPassword
    

    since the hosting provider doesn't use the SQLEXPRESS named instance (but most likely a default instance without any name). You need to ask your provider for the details - it could be that you have to provide some other instance name! That's totally up to the provider, we cannot know that - you'll have to ask and find out.

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