ASP.NET Web Api: Project requires SQL Server Express

折月煮酒 提交于 2019-12-20 16:10:09

问题


I created a Web API project under VS 2010. After I switched to VS 2012, I always get a warning:

The Web project 'xxx' requires SQL Server Express, whcih is not installed on this computer. [...]

I do not want to install this SQL Server Express. I use IIS for debugging. How can I disable this dependency?

I noticed also this in my web.config:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|[...].mdf;Initial Catalog=[...];Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

Who created this? Can I delete this?


回答1:


It was created by Visual Studio to you. The reason is Web API projects are a sub class of MVC projects. And actually, Web API project can contain both: a web application and Web API itself.

As far as this project is a sub class of an MVC project you get all this extra features.

You can delete all that extra stuff as far as you don't need it. The things you can delete also:

In WebConfig:

  • /configSections/section name="entityFramework"...
  • /connectionStrings
  • /system.web/pages
  • /system.web/profile
  • /system.web/membership
  • /system.web/roleManager
  • /entityFramework

You probably would also want to delete

NuGet packages:

Everything except razor, MVC, Web Api packages like:

  • jQuery
  • EntityFramework
  • jQuery Validation
  • jQuery UI
  • Modernizr
  • knockoutjs
  • MS Unobtrusive AJAX
  • MS Unobtrusive Validation

In Solution Explorer:

  • /App_Data
  • /Content
  • /Images
  • /Scripts
  • /Views

But be cautious, because after that deletion you won't be able to add Web API Help page for example (which describes your API).




回答2:


Change this part of the connection string "Data Source=.\SQLEXPRESS" to

"Data Source=localhost\SQLEXPRESS"




回答3:


you can also change the connection string to the new SQL 2014+ syntax "Data Source=(LocalDb)\MSSQLLocalDB;..." if you have a later version of SQL Express local db installed.



来源:https://stackoverflow.com/questions/13699921/asp-net-web-api-project-requires-sql-server-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!