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.
Related
I have created a website using ASP.net with simple data connection which is working fine in localhost. when I want to publish the same, I am getting this error. "Cannot open database "Abcdb" requested by the login. The login failed. Login failed for user 'XYZ-Domain\XYZ-SVR-01$'.
I don't have the user 'XYZ-Domain\XYZ-SVR-01$' in my SQL Server (SQL Express 2012).
I have my server in a virtual machine .
my connection string is "Data Source=XYZ-05-VM1\SQLEXPRESS;Integrated Security=True;Initial Catalog=Abcdb".
do I have to create a user in my database as shown above or else can I use existing database user. I am very new to this technology. Kindly help me.
Try it
<connectionStrings>
<add connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Abcdb;Integrated Security = SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
The error means that the server could be reached and the database name is correct. The problem is that the login is invalid.
From the login name I suppose that you have set Integrated Security=SSPI in your connection string and therefore try to authenticate with the account that your application is running under at the SQL Server. On your development machine, this is your user account that on a typical developer machine will be granted high access rights to the local SQL Server.
After you have deployed your application to IIS, it will run in an AppPool that is basically a process under a specific user account (the AppPool account). You need to grant this user account access to the database. In your case, this account is the Network Service account of the server you have your application deployed to. So you need to either grant the Network Service account access to the database or follow this - cleaner - approach:
Create a new Service account in your domain that is dedicated to your application.
Configure your AppPool to run under this account. Assert that the account has the minimum amount of access rights on the server that is possible.
Grant this account access to your database.
If you want to check the database connection settings, have a look at the connectionStrings section in your web.config. This link shows the available settings for 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.
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
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.
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.