Jenthe
Jenthe

Reputation: 797

How to create the Data Source property of the ConnectionString in ASP/net MVC?

I can't find a decent tutorial/blog that has a solution for my problem.

On my laptop I run a Microsoft SQLServer named 'SQLSERVER'. There's a database in it called 'SalesDB'. I can't figure out how to fill in the Data Source property of the ConnectionString in the web.config file in my ASP.NET MVC 4 application to get my application connected with the database.

This is the default connectionstring:

<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Labo7SQL-20131226161445;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Labo7SQL-20131226161445.mdf" />

Upvotes: 1

Views: 1593

Answers (2)

Leo
Leo

Reputation: 14820

The Data Source value should be the name (or ip address) of your sql sever. The Initial Catalog value should be the name of your database...SalesDB and you should remove the AttachDBFilename

Upvotes: 0

David
David

Reputation: 218828

connectionstrings.com tends to be a pretty useful resource for formatting a connection string. For MS SQL Server, you have a few options. Such as:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

or

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

or

Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;Password=myPassword;

Using the last one as an example, yours might be something like:

Server=localhost\SQLSERVER;Database=SalesDB;User Id=myUsername;Password=myPassword;

Upvotes: 4

Related Questions