Having problems with aspnetsqlmembershipprovider - asp.net

I have developed in asp.net for years and usually set up membership and roles in the same sql server database I use for cms. However, because I only need to password protect a couple of admin pages in my current project, I thought I would try the built in Account folder setup that Microsoft includes in its website template. So far it's been a nightmare.
I have the login working on my local machine, but when I uploaded to the server, I get the following error:
" 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)" The connection string provided by Microsoft says instance = true.
GoDaddy, the hosting provider, responded to my request to see if they could correct the connection string, by saying that the MDF file in the App_Data folder would only work on a dedicated server. (I'm skeptical...)
Making things even more challenging, I can open the sql express (.mdf) database and see the account I set up using the registration form. But when I try to test the default aspnetsqlmembershipprovider with the web configuration page inside my ap, I get a message saying:
Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.
I would really appreciate help in understanding what is happening so, if there isn't a duh solution, I can at least dismantle this thing in an intelligent way and then set up authentication in the webconfig, which would have taken ten minutes.
Many thanks.

Godaddy is wrong. Put your connection here and take a look at it for you. Remember to remove your login id and pwd in the connection string.

Related

Visual Studio login control produces A network-related or instance-specific error occurred while establishing a connection to SQL Server

I have been troubleshooting this issue for 5 days, so I think I may need some help.
In Visual Studio, I create a new project, select ASP.NET Web Application, and select the Empty template. I am able to drag a GridView object onto a page, select a SQL Server data source, and complete the setup of the GridView object. When I view the page in a browser, the DataGrid is displaying the data from SQL Server. This verifies that I am able to connect to SQL Server and display data.
I am able to drag a Login control onto a page. I set the authentication mode to Forms in the web.config file.
<system.web>
<authentication mode="Forms" />
</system.web>
I press Ctrl F5 to view the page in a browser. The Login object is displayed. When I enter a username and password and click the Login button, the page loads for about 1 minute, and then produces this error: 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).
I am using the machine that has Visual Studio, IIS and SQL Server Express installed, which should eliminate things such as remote connectivity. The problem persists if I disable Windows firewall. I do not have any additional hardware or software firewalls at play here.
Researching this using the book Beginning ASP.NET 4 by Imar Spaanjaars, Imar states that the Login control talks to the ASP.NET application service providers, which is a software layer that sits between the login control and the SQL Server database. The very first time you try to log in, the application service providers check to see if your application is using a database with the necessary database objects, such as the appropriate tables and roles. If not, the application service providers automatically creates the ASPNETDB.MDF. When I select the Login button, the ASPNETDB.MDF file is not automatically created.
One thing that caught my eye is that Imar Spaanjaars book states that the “application services providers sits between the login controls and SQL Server database.” However, this post on StackOverflow talks about having the login control use SQL Server instead of the MDF file. I am a little confused. I am not sure if there is some difference between and MDF file and SQL Server.
This and this article on StackOverflow state to ensure that Visual Studio is pointing to the correct instance of SQL Server. When I connect to SQL Server Express using SQL Server Management Studio, my Server name is WIMA1\WIMA1. In Visual Studio, I select Tools > Options, then select Database Tools > Data Connections, and I set the instance name to WIMA1\WIMA1.
This Microsoft Blog does a great job at explaining why this error appears. This article mentions that this error should only appear if you are using a named instance of SQL Server, which I am (WIMA1\WIMA1).
Some articles on StackOverflow mention that the connection to SQL Server must be done using SQL Server Authentication instead of Windows Authentication. Using SQL Server Management Studio, I am able to connect to SQL Server with both SQL Server Authentication and Windows Authentication. In Visual Studio, I add database1.mdf to the App_Data folder. I right-click the database1.mdf file and select Modify Connection. In the Modify Connection dialog box, if the Data source is Microsoft SQL Server Database File (SqlClient), the Test Connection is successful when using Windows Authentication. However, when using SQL Server Authentication, the following error appears: 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).
If I change the Data source to Microsoft SQL Server (SqlClient), I am able to successfully connect using both Windows Authentication and SQL Server Authentication.
I guess at this point I am in search of any thoughts or tips or suggestions that might help me to better understand what I can try to do next to resolve this so that I can use the Login control.

Granting sql server database access to IIS APPPOOL\DefaultAppPool

I have an ASP NET APP that's trying to access a sql server database, when I run it, I get an error saying
"Login Failed for user IIS APPPOOL\DefaultAppPool"
Searching the web I found that I should grant access to this user, so I executed the following script:
grant execute on schema :: dbo to [IIS APPPOOL\DefaultAppPool]
It executed succesfully as a script for my database, but I still get the "Login Failed" error.
What's missing?
Check the user your DefaultAppPool is using to connect.
On your IIS manager check DefaultAppPool advanced properties and look for Identity. You need to give it a user with enough privileges, depending on what your site is going to do.
I usually create different AppPools for different sites depending on what they will do, for example, if your app will write documents to a folder on your server, the user of the AppPool will need writing access to that folder.
Also is not a good idea to use an administrator user, as it could lead to potential security breaches. However it could be a good way to check if your problem comes from there.
I think I already know what it is. When I upgraded SQL Server Express, it installed a new server .\SQLEXPRESS (because I used "new sql instance"), remote connections where configured in this server and not LocalDB, my database was still in LocalDB. But now I get other error, maybe related to WCF Data Services...

Operating system error code 5(Access is denied.) when bulk insert

I have an ASP.NET application on Server A and a SQL Server on Server B.
When running the appliction it calls a stored procedure. This procedure try to bulk insert from a file from a shared folder on Server A, but the following error occured:
Cannot bulk load because the file "\serverA_address\sharedFolder\test.txt" could not be opened. Operating system error code 5(Access is denied.).
The strange is that when I execute the bulk insert from the sql management studio directly, it runs without any exeptions.
Another observation: if I change the shared folder address to a local folder where the sql server runs (Server B) without shareing, no access denied error...
I tried to set bulkadmin permission to all the users, including the technical users: sql_serviceusr who runs the sql service, another technical user who runs the application and make the call to sql server and to the user who logged in to the application. All users are domain accounts and all servers using Kerberos authentication.
Server A: Windows Server 2008R2
Server B: Windows Server 2008R2, SQL Server 2008R2
Appreciate any help or guidance.
You are doing a double hop, so you need to enable Kerberos delegation.
You could create a connect account and use SQL authentication.
In my experience, getting our network folks to properly set up Kerberos is like pulling teeth. We had it working for one glorious week once and then it suddenly stopped working. It just wasn't worth the hassle after that.
This might not be the exact answer you're looking for, but could be an interim solution for you.
By your description of the error, I assume the problem is in sharing the folder.
When sharing a folder, you should give access to the user who will be accessing the folder from remote computer in two places in folder's properties: under the Share tab and under Security tab.
Did you give access in both of them?

Can't connect to Sql Server

Im getting this error on the production server:
A network-related or instance-specific error occurred while establishing a > connection to SQL Server.
It's on IIS, and connecting to sql server with Windows authentication.
Any idea? or solutions?
The error message listed in the question typically occurs to me when I'm having connection issues, not related to credentials. Is your connection string setup properly? Have you tested it out on a different machine?
Additionally though, with windows authentiation in place, updated the web.config to set:
<identity impersonate="true"/>
solves the issue since the web application impersonates the person using the application, and their credentials have already been verified and are passed on to SQL Server.
Are you sure the production server has access to the relevant SQL Server? You can easily use the ODBC Data Source Administrator to test that this is so.
if it is a web application and you do not use impersonation, the application will try to connect with the IIS user, most likely NETWORK SERVICE, b/c that is the user that is running the app. My suggestion is to either use impersonation (see Dillie's post) or create an application user name and password and use that. I personally prefer application user names for most cases.

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