ASP.NET Web Api: Project requires SQL Server Express
Asked Answered
V

3

47

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?

Vermis answered 4/12, 2012 at 9:43 Comment(1)
Create an Empty Web Application and install Microsoft.AspNet.WebApi NuGet package. You are good to go. Don't use MVC templates for real world stuff. It is just unnecessary.Illogical
P
20

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).

Platino answered 4/12, 2012 at 19:7 Comment(1)
While this is good knowledge to have to clean up your project, nothing here fixes the error.Loach
E
93

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

"Data Source=localhost\SQLEXPRESS"

Exclusive answered 5/9, 2013 at 3:6 Comment(8)
This should be the correct answer. It is concise and answers the OP question.Chalkboard
Although not completely related, I was being prompted to upgrade to SQLExpress which I then swapped out for LocalDB '(localdb)\ProjectsV12' this tip helped bridge the gapKinsler
Are you saying that Visual Studio looks for the string ".\SQLEXPRESS" in the app.config files, and if it finds it, it displays this warning? If so that's really dumb.Lesbos
@MobyDisk probably not that simple but yes its winter 2016 and this still fixes the issueMatrices
What I don't get is that I have SQL Express installed and the . in the connection string STILL causes that warning. If I ignore it and just keep working, everything works correctly. Seems like quite the useless bit of "functionality"Singhalese
@StephenPatten I guess VS looks form the period as I have a different database name than SQLEXPRESS and just changed the period to localhost and VS 2017 v.15.3.2 does not hang any more when loading my web projet. @WesP Change the period to localhost as the answerer writes.Osteophyte
As I understand the OP's question it is the same as mine. I don't use SQLExpress in my project. I have never used SQLExpress in my project. So why would I change a connection string to look for a db connection that I've never had and don't want? Seems to me the answer is to remove the Default connection and leave only those strings that refer to the actual SQ2014 database instance.Barrus
This is definitely the answer. It's also something that VS is not going to fix in future versions. developercommunity.visualstudio.com/content/problem/18990/…Benzvi
P
20

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).

Platino answered 4/12, 2012 at 19:7 Comment(1)
While this is good knowledge to have to clean up your project, nothing here fixes the error.Loach
T
5

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.

Trilbie answered 1/11, 2016 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.