Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web Api: Project requires SQL Server Express

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?

like image 838
user437899 Avatar asked Dec 04 '12 09:12

user437899


People also ask

How to Add SQL Server Database to ASP net project?

The next step is to create the ASP.NET membership and School databases. From the View menu select Server Explorer (Database Explorer in Visual Web Developer), and then right-click Data Connections and select Create New SQL Server Database. In the Create New SQL Server Database dialog box, enter ".

Can we use Web API with ASP NET web form?

Although ASP.NET Web API is packaged with ASP.NET MVC, it is easy to add Web API to a traditional ASP.NET Web Forms application. To use Web API in a Web Forms application, there are two main steps: Add a Web API controller that derives from the ApiController class. Add a route table to the Application_Start method.

Can we create Web API without MVC?

An API is supposed to provide services without being coupled with its consumer application. There is a common misconception that for developing Web APIs, we have to go by ASP.NET MVC application. In this article, we will develop an independent API which is not coupled with a ASP.NET MVC application type.


3 Answers

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

"Data Source=localhost\SQLEXPRESS"

like image 191
Stevodevo Avatar answered Oct 04 '22 19:10

Stevodevo


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

like image 25
Max Shmelev Avatar answered Sep 30 '22 19:09

Max Shmelev


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.

like image 37
Bob Provencher Avatar answered Sep 30 '22 19:09

Bob Provencher