Which connection string WSAT uses - asp.net-mvc

I create a new ASP.NET MVC project with internet template.
I build the solution.
I open ASP.NET Web Site Administration Tool (WSAT).
I click the security tab
I get this error:
"Unable to connect to SQL Server database."
I am using Visual Studio 2012 and SQLServer Express 2012.
I don't have IIS installed (other then what ships with Visual Studio).
The Connection String from the new project:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication2-20130804051506;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication2-20130804051506.mdf" providerName="System.Data.SqlClient" />
It is worth mentioning that I did not change anything in the web.config after its initial creation and that MVC project seems to be working properly e.g. I am able to register and login and then see that data in the (LocalDb)\v11.0.
I read on other posts that the connection string from machine.config is sometimes used instead of the one from web.config.
I have a two machine.config files, one under C:\Windows\Microsoft.NET\Framework\config\v4.0.30319 and the other under C:\Windows\Microsoft.NET\Framework\CONFIG\v2.0.50727
When is a machine.config's connection string is used instead of my web.config's connection string?
I want to use the (LocalDb)\v11.0 data source, why does WSAT unable to connect to it?

From http://forums.asp.net/t/1483981.aspx/1 :
by default, the membership / role provider uses the "localSQLServer" connection string which is set to point to a local SQL Express database from the root web.config. In most cases, the server do not have SQL express installed and you will get this error.
By clearing the connection strings should reveal those errors.

Related

How to use existing SQL database in my separate project under one solution in ASP.NET MVC application

I have created 2 separate projects under one solution where one project is a class library. I have created an ADO.NET Entity Model from my existing database into this. Another project is an ASP.NET MVC web app.
I have used Individual User Authentication and wanted to use registration and login facility provided by this.
Now I am unable to use my existing database as this project is creating new database by itself when first runs.
Please guide me how to use existing database. I have given reference to my ASP.NET MVC project. These are my connection strings. Please help me.
<connectionStrings>
<add name="LAPTOP-71D4QMB6"
connectionString="Data Source=LAPTOP-71D4QMB6;Initial Catalog=VCAdvertiserDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="HBDBEntities"
connectionString="metadata=res://*/Data.HBModel.csdl|res://*/Data.HBModel.ssdl|res://*/Data.HBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=LAPTOP-71D4QMB6;initial catalog=VCAdvertiserDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
Error thrown is:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
You have to copy the connection string from the app.config of your class library to the web.config of the MVC project. You need to put it in both the root web.config and also have to put it in the shared web.config under the shared views folder. That last may not be needed but it also doesn't hurt.
That worked for me.
Joey

A downgrade path is not supported convert version 782 to 706 and earlier

I am creating one application where I have used ASP.NET MVC with Entity Framework 4.5.2 and trying to access the SQL Server but it gives me an error that I can't access any database so I just convert it to the single user mode.
Now after converting it to Single User mode the new error comes when I am trying to access in Server Explorer, Data Connections (Default Connection), it shows me the below dialog. I am not understand what is going wrong.
I have SQL Server version 11.0.2100.60.
Please some one help me to solve this issue!
This worked for me (using Visual Studio 2015 community)...
In Server Explorer right-click the desired connection and select Modify Connection
Select Advanced Options
Change the Data Source to a different version (In my case it needed to be SQL express) press OK.
Hope it helps
Ufffff after so many solutions applied I found one from it.
Steps:
1) Change Instance name in Visual Studio Link:
Under Tools > Options > Database Tools > Data Connections > SQL Server Instance Name.
set (LocalDB)\MSSQLLocalDB
2) Change your connection string:
From:
<add name="DefaultConnection" connectionString="Data Source=./SQLExpress;AttachDbFilename=|DataDirectory|\DBName.Service-20160924032113.mdf;Initial Catalog=DBName.Service-20160924032113;Integrated Security=True;"providerName="System.Data.SqlClient" />
To:
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DBName.Service-20160924032113.mdf;Initial Catalog=DBName.Service-20160924032113;Integrated Security=True;"providerName="System.Data.SqlClient" />
3) Remove User Instance=True from Connection String.
Thanks to James P and Mark Homer for excellent response.

how to create tables on azure and connect them with VS2013

I have built my MVC 5 project with a database using entity framework db first. I published my website but had problems with my database.after lots of research to solve the problem,i figured to build my database on azure since it's only 2 tables and copied the connection string to the web.config file on my MVC 5 project.
when publishing again with the new connection string update, an error showed indicating that can't find the database:
The system cannot find the file specified
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified
This is what the azure offered me as a connection String:
Server=tcp:idud662mdp.database.windows.net,1433;Database=sportsMArAiCkhuw;User ID=sportsMania#idud662mdp;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
I have modified it and this is my connectionString:
<add name="DataEntryNew" connectionString ="Data Source=idud662mdp.database.windows.net;Database=sportsMArAiCkhuw;User ID=sportsMania#idud662mdp;Password=My-Pass;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient"/>
What's going wrong?
Your connection string is not the same one as provided by Azure. Try changing the DataEntryNew tag in the web.config file to:
<add name="DataEntryNew" connectionString ="Server=tcp:idud662mdp.database.windows.net,1433;Database=sportsMArAiCkhuw;User ID=sportsMania#idud662mdp;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient"/>

SQL Server Database item in VS08 without SQL Server Express

I've encountered this problem (while trying to add SQL Server Database (.mdf) file to my asp.net mvc project):
Connections to SQL Server files (.mdf) require SQL Server Express 2005 to function properly. Please verify the installation of the component or download from the URL: http://go.microsoft.com/fwlink/?LinkId=49251*
I have SQL Server 2008. Does anyone know how to add that file to a project?
If you are using SQL Developer, Standard, or any other version aside from Express you need to attach the database to the SQL server before you can use it. In SQL management studio connect to your server, right click on the Databases folder and choose attach, browse to your database and select it (note that you may need to move it to a directory SQL can see - by default SQL runs as Network Service and cannot peer inside C:\Users).
Once you've done that you need to tell ASP.NET that is the database you wish to use. There are a few ways to do this but by fair the easiest is to override the SQL Express database connection by adding the following to your web.config
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Don't forget to give Network Service, or whatever identity you run your application pool as, access to the database in SQL server.
(I believe this will work.)
Move the MDF file to the SQL Server box and use Management studio to attach it, thus creating a database in SQL Server. (You will need to create a transaction log file to go with it.)
Then connect to that database as data source.
Full SQL Server cannot use a connection to a database file specified in the connection string.

Default MVC Web Application Database

When setting up a new ASP.NET MVC Web Application, the default connection string inside Web.Config is something like this:
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
I'm just wanting to play around with logging in and registering, etc but when I run the app it obviously can't find a SQL database. What database with what tables do I need to setup to do this?
I have SQL Server 2005 Standard installed on my system, is that enough?
Thanks.
SQL Server 2005 is more than enough. The default connection string is looking for a SQL Server Express file in the App_Data folder. Replace it with the following:
Data Source=<server name>;Initial Catalog=<database name>;User Id=<user name>;Password=<password>;
If you want to generate the ASP.NET membership tables then run aspnet_regsql.exe, which is found in the .NET 2.0 framework folder (e.g. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727). A wizard will guide you through the process.

Resources