SQL Server Database item in VS08 without SQL Server Express - asp.net-mvc

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.

Related

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.

A network-releated or instance-specific error occurred while establishing a connection to SQL Server

I have a simple mvc web site (using the VS internet template) on azurewebsites talking to a SQL Azure database in the same data center. The database at this time is just to do the built-in SimpleMembership Provider. I have already switched from the default App_Data mdf file to Azure SQL. It works fine, but sometimes after a while, it would give:
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)
with a long message:
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance
using a database location within the application's App_Data directory.
The provider attempted to automatically create the application
services database because the provider determined that the database
does not exist. The following configuration requirements are necessary
to successfully check for existence of the application services
database and automatically create the application services database:
But I do not have a connection string using SQL Server Express!
Restarting the web site immediately does not remove the error.
Without changing anything and restarting the web site 15 minutes later give:
502 - Web server received an invalid response while acting as a
gateway or proxy server.
There is a problem with the page you are looking for, and it cannot be
displayed. When the Web server (while acting as a gateway or proxy)
contacted the upstream content server, it received an invalid response
from the content server.
Previously, I could restore the website back to working order by just re-publshing from VS. But for the last hour I have tried and tried and I cannot get the web site to work again.
What is the problem about SQL Server Express really about?
My connection string section contains:
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=tcp:sabl6h4---.database.windows.net,1433;Database=MVC;User ID=test#sabl6h4---;Password=----;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.SqlClient" />
<add name="Entities" connectionString="metadata=res://*/Data.Model1.csdl|res://*/Data.Model1.ssdl|res://*/Data.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=sabl6h4---.database.windows.net;initial catalog=MVC;user id=test;password=----;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Just to be sure, I copied and pasted sabl6h4---.database.windows.net into SSMS and connected using login test and it opened the database without problem.
One day later: I created a new azurewebsite and published the exact same project and same web.config. It works fine without problems. After some minutes, the exact same error occurred!
Three more hours later: Went for lunch, came back, hit the browser Refresh button, and the web site is up again. I am convinced that someone is fooling around with the settings at the back end.
Add a <clear/> element as the first element under the connectionstrings element to ensure no strings are being inherited. Also, I assume your Azure SQL DB is set up with proper firewall settings allowing your IP where the ASP.net code is deployed?
I also had this error. But in my case I did not notice that the connection string was being overwritten by the publish wizard. I fixed the problem by going to the Settings tab in the Publish wizard and unchecking "Use this connection string at runtime (update destination web.config)"

Which connection string WSAT uses

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.

How do I connect to a code-first created localdb database using database explorer?

I have a database in an MVC 4 project that has so far been entirely managed via Code First and Migrations. I now want to go in and change some of the data by hand. How can I connect to the localdb instance using Database Explorer within Visual Studio 2012? The connection string is as follows:
Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-mydb-20120830192823;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-mydb-20120830192823.mdf
I have an App_Data folder in my project, but the .mdf named in the connection string is not in there.
I have tried connecting to '(LocalDb)', 'LocalDb', '.SQLEXPRESS' and various other things in the Add Connection dialog, but nothing seems to work.
Duh, it was '.\SQLEXPRESS' I needed to connect to.

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