ASP.NET Membership provider SQL Server Express - asp.net

Is there any problem with using ASP.NET Membership via SQL Server Express ?
When I use this code :
Roles.AddUserToRole("shah", "Admdin")
I am faced with the error shown below.
Config :
OS : windows 7 64 bit.
SQL Server version: SQL Server Express Edition, Version :9.00.4035.00
connectionString="Data Source=.\sqlexpress;Initial Catalog=MShop;Integrated Security=True"
The user instance login flag is not supported on this version of SQL
Server. The connection will be closed. Description: An unhandled
exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and
where it originated in the code.
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:
If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable
automatic creation of the provider database. Additional information is
available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the
application's App_Data directory does not already exist, the web
server account must have read and write access to the application's
directory. This is necessary because the web server account will
automatically create the App_Data directory if it does not already
exist.
If the application's App_Data directory already exists, the web server account only requires read and write access to the
application's App_Data directory. This is necessary because the web
server account will attempt to verify that the Sql Server Express
database already exists within the application's App_Data directory.
Revoking read access on the App_Data directory from the web server
account will prevent the provider from correctly determining if the
Sql Server Express database already exists. This will cause an error
when the provider attempts to create a duplicate of an already
existing database. Write access is required because the web server
account's credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a
local user profile for both machine and domain accounts.

Yes, you can use membership with SQL Express. I think you do not have your Roles configured correctly in web.config. The error indicates it's trying to create the database, but the database should already exist if you are trying to add a role to a user,
You must create the user first, then add them to the role, if the database doesn't exist then either you didn't create the user first, or your roles are configured to use a database that doesn't exist.

Related

ASP.NET built-in User Authentication production connection string

I am using ASP.NET built-in methods for User Authentication and Membership which uses a SQL Server flat file (.mdf) which is stored in the App_Data folder of my project solution.
I have this working locally, but when I deploy to Virtual Private Server (VPS) I am getting the following error message:
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 connection string:
<add name="DefaultConnection" connectionString="Data Source=IP_ADDRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;Connect Timeout=30 User ID=USERNAME;Password=PASSWORD" providerName="System.Data.SqlClient"/>
I don't use local .mdf files for SQL server, but try the following:
<add name="DefaultConnection" connectionString="AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Connect Timeout=30;User ID=USERNAME;Password=PASSWORD" providerName="System.Data.SqlClient"/>
Try that locally and see if it works. If it works locally, then try it on your VPS. I'm making the guess that for a local file, "Integrated Security" doesn't matter. Also, you were missing a ; before User ID, and I'm not sure why the IP address would matter for a local file.
Fixed the semi-colon and still showing the same error message but now also:
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:
If the application is running on either Windows 7 or Windows Server
2008R2, special configuration steps are necessary to enable automatic
creation of the provider database. Additional information is available
at: http://go.microsoft.com/fwlink/?LinkId=160102. If the
application's App_Data directory does not already exist, the web
server account must have read and write access to the application's
directory. This is necessary because the web server account will
automatically create the App_Data directory if it does not already
exist. If the application's App_Data directory already exists, the web
server account only requires read and write access to the
application's App_Data directory. This is necessary because the web
server account will attempt to verify that the Sql Server Express
database already exists within the application's App_Data directory.
Revoking read access on the App_Data directory from the web server
account will prevent the provider from correctly determining if the
Sql Server Express database already exists. This will cause an error
when the provider attempts to create a duplicate of an already
existing database. Write access is required because the web server
account's credentials are used when creating the new database. Sql
Server Express must be installed on the machine. The process identity
for the web server account must have a local user profile. See the
readme document for details on how to create a local user profile for
both machine and domain accounts.

connect mvc3 application to remote sql server

i publish an mvc3 application on a webserver IIS7 and i want to connect my application with a remote SQL server ( different machine)
here is my connection string:
connectionstring="server=server;database=db;user Id=user;password=psw;user instance=false" providername="System.Data.SqlClient"
i m using entityframework.
i also added the user in the connectionstring to security folder under database in sql management studio with dbo rights.
the problem is i get an error : failed to open a session for the user
SQL exception (0x80131904)
Have you checked the user mapping for the login?
You can find the logins under the server folder security -> logins.
Check there is a login mapped to the database user. Select the appropriate login -> properties -> user mapping tab.
The fact that a user exists in a database, does not directly mean that there is a valid login associated with that user. Ensure that a login maps to the database user and that the user has the required database role.
After hours of research i just figure out that adding the whole groupe of computers (Domain\Computers) granted me the access to the database. i changed my connectionstring to use integrated security= sspi. From the beginning it was a Connection problem.

SQL error after deploy ASP app

Hi I have the problem to successfully log in my application after deploy.
I am using ASP MVC default login and membership provider and it is working on my localhost.
But after deploy I am trying to log in, then error is shown.
*
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)
*Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
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:
If the
application is running on either Windows 7 or Windows Server 2008R2,
special configuration steps are necessary to enable automatic creation
of the provider database. Additional information is available at:
http://go.microsoft.com/fwlink/?LinkId=160102.
If the application's
App_Data directory does not already exist, the web server account must
have read and write access to the application's directory. This is
necessary because the web server account will automatically create the
App_Data directory if it does not already exist. If the application's
App_Data directory already exists, the web server account only
requires read and write access to the application's App_Data
directory. This is necessary because the web server account will
attempt to verify that the Sql Server Express database already exists
within the application's App_Data directory. Revoking read access on
the App_Data directory from the web server account will prevent the
provider from correctly determining if the Sql Server Express database
already exists. This will cause an error when the provider attempts to
create a duplicate of an already existing database. Write access is
required because the web server account's credentials are used when
creating the new database.
Sql Server Express must be installed on the
machine.
The process identity for the web server account must have a
local user profile. See the readme document for details on how to
create a local user profile for both machine and domain accounts.*
*
If anyone knows how to resolve this, I will be really happy.
Thank you!
if you deploy this to an external webserver you must adjust your connectionstring settings in the web.config

Attaching mdf file into sql server

Earlier mdf file was in app_Data folder, and application was working fine.
When I attached mdf file into sql server. I can execute queries. But when I try to use it from asp.net application it give following exception.
Cannot open user default database. Login failed.
Login failed for user 'domain\username'
So if I understand correctly you no longer specify the AttachDBFilename but instead you have attached the database 'for real' to an existing SQL Server instance.
since you are no longer conencting to your own personal RANU instance, your application must have proper credentials to connect to the SQL Server instance where you attached the database. The correct solution depends on a number of factors, but possible answers are:
create a SQL Server login for the ASP app pool identity and grant this loggin proper access to the required database. Use CREATE LOGIN [domain\user] FROM WINDOWS and CREATE USER [domain\user]. Better still, for extra credit, add the app pool identity to a security group and grant this security group the needed permission.
change the app pool identity to an indetity that has the proper permissions already granted
if the ASP application uses impersonation and the SQL Server instance is on a different machine from the ASP application, make sure your ASP app pool is allowed to do constrained delegation.
That error indicates that you are trying to use Intergrated Security. Depending on your version of IIS and your configuration, you are probably trying to connect to the database with the IUSR or NETWORK SERVICE accounts.
The simplest fix is to use SQL Authentication. Include a SQL account username/password in your connection string.

Login failing on live server - asp.net

I am new to asp.net and am trying to test my first site on a production server.
What I have is a login control "login.aspx" that after successful login redirects the user to an admin area of the site.
When I test the site using VS2008 on my Windows XP machine all works well and I can login and administer the site. I am using Forms authentication to process the login.
When I upload the site to the production server it is a different story. I can access the login.aspx page. When I enter my login details and click "Login" it takes a really long time to process the page and eventially the page fails.
This is the error that I am getting:
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)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the applications 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:
If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
Can anybody please help me on this issue.
Have you actually read the error message? It says exactly what is wrong, and how to fix it :-)
It clearly states "The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist."
Ergo, the database that is referenced in the web.config file was not uploaded to the production site.
Upload it to App_Data, and get back to us.
-Oisin
p.s. the connection string is in Web.config.

Resources