Minimum requirements to use AspNetSqlMembershipProvider - asp.net

I'm using an AspNetSqlMembershipProvider for my application.
On my development machine I recently deinstalled SQL Server 2005 Express and Management Studio Express so that I could install the full version of Management Studio. I chose not to install SQL Server 2005 because, well, I don't want to have unnecessary things running on my machine.
Now whenever my code attempts to do anything that relates to authentication I get an error of:
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)
So, what is the minimum amount of SQL Server I have to install in order for this to work?

You could get away without having any SQL Server instances installed, especially if all you're using it for is Membership, Roles and the default Profiles.
The default connection string often looks like this:
<connectionStrings>
<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
If you change your SQL connection string, to match the value of "connectionString" above, that will force ASP.NET to generate the standard ASP.NET database for you withing the "App_Data" folder of your site - the keep part is "AttachDBFilename" which tells it to open the mdf file directly rather than attach to a SQL instance.
However, you might have some difficulty connecting to that file with SQL Management Studio.
You'll probably have to change the connection string once you move the site off development and into production, to point to a full instance of SQL if you so wish, rather than stick with the file based version.
Alternatively, what I tend do is have SQL Server installed (Express or otherwise), but the services stopped unless I'm actually using them. Then I just start them up when I'm developing.
Also you can have the Express version of SQL Server installed on the same machine as theh the full version SQL Management Studio without any problems.

Related

ASP.NET cannot connect to SQL Server database on the same machine

I have a local SQL Server database setup on a Dell R720 running Windows Server 2012 R2 and I am developing an ASP.NET site. I am able to connect to the database and pull in objects and queries and everything EXCEPT when I try to pull in the login tool.
I was following a tutorial on creating a login page and they suggested pulling in this tool, and clicking the login button which will prompt visual studio to create a new database with a bunch of tables in it, which they did successfully in the video but when I try it, I get this response:
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)
Here is my web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="SOSiQConnectionString"
connectionString="Data Source=KINGDOM_NETWORK;Initial Catalog=SOSiQ;Integrated Security=true;"
providerName="System.Data.SqlClient" />
<!-- commented this out testing the connection
<add name="SOSiQConnectionString1"
connectionString="Data Source=localhost\;Initial Catalog=SOSiQ;Integrated Security=True"
providerName="System.Data.SqlClient" /> -->
</connectionStrings>
Visual studio code showing SQL Server database connection
PS, I have searched google for days looking for a solution. Everybody suggests making sure that you have remote connections enabled and firewall/ports. I've done all that to no avail, but, in my mind it shouldn't matter because A. I am on the machine that has the SQL Server database and B. I can access the database from my project in Visual Studio.
Download SQL Server Express, even if you have a Standard or an Enterprise version already.

Connect to LocalDB (Visual Studio 2013) from SSMS 2014

I'm confused about how to connect to LocalDb from SQL Server 2014 Management Studio. (I also have SQL Standard Edition installed on localhost.)
I have a connection in my ASP.NET application like this:
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\BillTest.mdf;Initial Catalog=BillTest;Integrated Security=True"
providerName="System.Data.SqlClient" />
When I go into SSMS 2014 and connect to (LocalDb)\v11.0 I can connect and I see a database like aspnet-BillTest-2015mmddhhmmss but I can't open it. I get an error like "the database ... is not accessible."
When I connect to (LocalDb)\mssqllocaldb I can connect, and I see a DB like BillContext and there are my tables. I verified this is the one the app is connected to, by inserting new rows and seeing them show up in my app.
Can you explain the discrepancy in connect strings:
how is my ASP.NET application using (LocalDb)\mssqllocaldb when the connect string in Web.config is (LocalDb)\v11.0? What is actually on \v11.0?
And why does (LocalDb)\mssqllocaldb point to a SQL version (12.0.2000) that is neither 11.0 nor my SQL Server 2014 installation (localhost = 12.0.4100.1)?
why is the DB name "BillContext" instead of "BillTest"?
It's because of the LocalDB Server Version and SSMS version. Till Visual Studio 2013 you were supposed to use version specific connection strings (e.g (LocalDb\v11.0) from Visual Studio 2015 onwards you are supposed to use version independent connection strings (LocalDB\MSSQLDB) in order to work properly. Check this link for reference.
Version independent local DB in Visual Studio 2015 - Bill Wagner
why does (LocalDb)\v11.0 work from my ASP.NET application but not within SSMS?
It sounds like (LocalDb)\v11.0 is accessible from both from what you describe, it's just that the database itself isn't accessible. I'd check if the file still exists or if something else has locked the file.
why does (LocalDb)\mssqllocaldb point to a version (12.0.2000) that is neither 11.0 nor my SQL Server 2014 installation (localhost = 12.0.4100.1)?
Assembly version and file version are different. See this answer
why is the DB name "BillContext" instead of "BillTest"?
You're probably not providing a connection name to the EF context (e.g. new BillContext("DefaultConnection")) so it's falling back to the default, which is a LocalDb database named after your context.
https://msdn.microsoft.com/en-us/data/jj592674
https://msdn.microsoft.com/en-us/data/jj591621.aspx

SQL Server mdf file cannot be connected by both ASP.NET application and SQL Server Management Studio

I have a simple ASP.NET website application. Using the new Entity Framework model-first approach, I created a database (.mdf file). However, whenever the application is running, SSMS cannot connect to the database (error 5123 or 5120), and vice versa.
Is this normal? Is there a way to get around this?
I have tried to run SSMS as Administrator, but that did not seem to help.
I am using VS 2012 Professional and SQL Server 2012 Express.
Here is the connection string of the app.
<connectionStrings>
<add name="MarketingContainer"
connectionString="metadata=res://*/App_Code.Marketing.csdl|res://*/App_Code.Marketing.ssdl|res://*/App_Code.Marketing.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQL2012ADV\MSSQL\DATA\MarketingDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient"/>
</connectionStrings>
When you use AttachDbFileName you place a lock to the file and use as single user mode and only one connection can use the database.
For use the database between Visual Studio and SQL Server you must:
1. Attach the database (not the file) to SQL Server
2. Use the connection string to point to SQL Server
Max answer is in principle correct. I have now implemented his answer, using this connection string
add name="MarketingContainer" connectionString="metadata=res://*/App_Code.Marketing.csdl|res://*/App_Code.Marketing.ssdl|res://*/App_Code.Marketing.msl;provider=System.Data.SqlClient;provider connection string="data source=SQLSERVERNAME;initial catalog=DATABASENAME;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"
I should note that the reason that my problem arose in the first place was this. I use VS2012 to create an entity data model (edmx file). after I get the model to where I want it, I generate the database from model. at that point, the Generate Database Wizard shows up. New Connection. Change Data Source. I choose Microsoft SQL Server Database File (because I only had a mdf file at that point). If you do it this way, you end up with the application using LocalDB, and Attachdbfilename locks the file as Max said. However, what I should have done is first use SSMS to attach to the mdf file, and then rename the database as needed. and then in VS2012, Change Data Source, select Microsoft SQL Server instead. and now, both VS2012 and SSMS can access the database.

SQL Server 2012 connection string: can no longer find Server?

I just installed VS2012 pro RC and SQL server Express 2012. I go to run my app and I get this error:
The Data Source value in the connection sting specifies an instance of SQL Server
that is not installed. To resolve this issue, you can either choose to install
the matching instance of SQL Server or modify the Data Source value in the
connection string.
I used VS2012 Developer preview for a long time and it used to work just fine. This is the connection string that's in the web.config file:
<add name="MySiteDBConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MySiteDB.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"/>
When I go to Management Studio, I get the error message below. When I go to browse for servers, the list is empty.
Where's the problem and how do I solve it?
Thanks.
You need to make sure the SQL Server service is running. Visual Studio might be spinning it up for you when you establish a connection using web.config and that silly AttachDbFileName feature. Check your Services Control Panel applet and make sure that SQL Server (SQLEXPRESS) is running. If it isn't running, start it.
While you're there, it can't hurt to make sure the SQL Browser service is running.
It also can't hurt to use the proper case. If the instance is called SQLEXPRESS then don't call it SqlExpress or SQLExpress. I've never heard of this breaking connectivity, but be consistent. You might also try other variations just in case:
(local)\SQLEXPRESS
localhost\SQLEXPRESS
127.0.0.1\SQLEXPRESS
Your_Computer_Name\SQLEXPRESS
You should also verify what connection protocols are enabled for this instance. Go to Start > Programs > SQL Server > Configuration Tools > Configuration Manager, expand SQL Server Network Configuration, and highlight Protocols for SQLEXPRESS - on the right you should see Shared Memory, Named Pipes, TCP/IP. Which of these are enabled?
EDIT
You should download SQL Server 2012 Express from here. Install it. Then create a database. Point Visual Studio at that database. Stop, and I really mean STOP, using the User Instance and AttachDbFileName features. These things are supposed to make development easier but at the end of the day they do little but make development a royal pain in the rear.
Another option is to use SqlLocalDb for local development. Last month I wrote a thorough "Getting Started" tutorial that may help.

Failed to generate a user instance of SQL Server

I been trying to get my Visual Studio 2008 to run my Web Application on IIS7 on my Windows 7 machine but I just can't get it to work. I'm using the SQLEXPRESS I been following this Tutorial, but I get the following error message.
"Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed."
my connectionString seem to be ok
<add name="testConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|test.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
The site run with out database connection.
Any ideas and thoughts about this?
Thanks guys
Make sure the instance name is called "SQLEXPRESS" exactly.
Make sure the "test.mdf" file exists in the "App_Data" folder.
When you are adding the DB using Server Explorer, use "Test Connection" first.
In IIS7,
they use default asp.net database.
create a new application pool instead of using default.
and keep your database in that.
go to sql configuration manager and in the properties,select local system instead of build in system.
Now,it may work.

Resources