1

I just setup up member ship roles and registration on my website with visual web developer using the tutorial on msdn. It works perfectly locally, but when i uploaded it to my server, I get the following page:

"Server Error in '/' Application.
--------------------------------------------------------------------------------
Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Source Error: 
[No relevant source lines]
Source File: machine.config Line: 160 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4016 "

Does anybody know why I'm seeing this and how I may go about fixinf this? Any help is greatly appreciated.

Thank you

Bael.

EDIT:

I have just looked at my web.config file after reading the following line in the error message: "The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty." ... And have noticed that the following element is completely empty:

<connectionStrings/> // Is this one supposed to be empty? if not what should go here? In the error it implies it shouldn't be empty. Also, I don't know where I should place LocalSqlServer

LATEST EDIT

After changing DataSource to LocalHost i get the following error:

Server Error in '/JTS' Application.
--------------------------------------------------------------------------------
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 
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. 
Exception Details: System.Data.SqlClient.SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 
Stack Trace: 
[SqlException (0x80131904): 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849015
 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4862333
 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
 System.Data.SqlClient.SqlConnection.Open() +122
 System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +87
 System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +221
 System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +815
 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105
 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42
 System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +78
 System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e) +60
 System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +119
 System.Web.UI.WebControls.Login.AttemptLogin() +115
 System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927 
Georg Fritzsche
99.3k26 gold badges197 silver badges238 bronze badges
asked Jan 20, 2010 at 10:24
4
  • Are you using a role provider? Commented Jan 20, 2010 at 10:34
  • yeah i am using a role provider :) Commented Jan 20, 2010 at 10:40
  • 2
    Do you have SQL Server installed? Commented Jan 26, 2010 at 2:26
  • Do you actually have an instance of SQL Server running on the server (or on some other machine it can reach)? You need that in order to make this work. Commented Jan 29, 2010 at 23:40

6 Answers 6

9

Ensure you have connection string named LocalSqlServer added connectionStrings element of your Web.config.

If you're using standard ASP.NET Membership/Role providers, by default they are declared as this:

<membership>
 <providers>
 <add
 name="AspNetSqlMembershipProvider"
 type="System.Web.Security.SqlMembershipProvider, ..."
 connectionStringName="LocalSqlServer" ...

It's the connectionStringName which is likely to be causing this error. If you plan on using Membership/Role API, you'll have to either add a connection string named LocalSqlServer to <connectionString> secion of your Web.config, or change connectionStringAttribute so that its value will be a valid (and existing) connection string name.

answered Jan 20, 2010 at 10:26
5
  • 1
    For some more information on this see support.discountasp.net/KB/a337/… Commented Jan 20, 2010 at 10:36
  • i'm sorry but i don't comletely understand. what am i supposed to add to the connectionsString element? Commented Jan 20, 2010 at 11:02
  • @bastijn, i follwed the instructions on that site and in msdos it said something about a network-related or instance-specific error occured. the error's even bigger now that i've changed it... Commented Jan 20, 2010 at 11:21
  • 2
    The amount of error text does say nothing about the error itself, remember that forever :). Commented Jan 20, 2010 at 12:44
  • thanks i'll make sure to remember that! :D ..it sure can seem a little scary though lol Commented Jan 20, 2010 at 12:49
3
+250

LocalSqlServer is a default connection string entry in machine.config. It is always present although not in the app/web config file.

It points to your local instance of sqlexpress that was installed with visual studio.

By default the membership provider, upon configuration, creates a local .mdf file in your app_data folder (click show all files). This database has been provisioned.

If for some reason you want to use a different database you must provision it with aspnet_regsql.exe . You will find it in your windows/microsoft.net/framework/2.0.xxxx directory.

from the commandline run aspnet_regsql.exe /? to get instructions.

So.. this may be why you are getting these errors. If you DO want to use a different database and do not want to edit the membership section to point to the new db you must remove localSqlServer and then re-add

OR, again, configure your membership element to point to a different connection.

EITHER WAY you need a PROVISIONED database other than the local user instance that was provisioned by VS that you are using during development and a connection string that points to it.

<connectionStrings>
 <remove name='LocalSqlServer' />
 <add name='LocalSqlServer' connectionString='Data Source=DBServerName;
 Integrated Security=false;Initial Catalog=DBName;
 User ID=DBLogin;Password=DBPassword' providerName='System.Data.SqlClient' />
</connectionStrings>

EDIT: reread your question:

The problem is that the host does not have sql or does not allow user instances. Typically in a hosted site, you will request a database and upon getting the credentials, use aspnet_regsql.exe to provision that database. In this case you MUST modify the membership section in web.config to point to your new database.

hth

answered Jan 26, 2010 at 23:16
2
  • By default LocalSqlServer is defined in the machine.config, however many hosts will remove that entry. Commented Jan 26, 2010 at 23:30
  • yes, you are right ben. @BAEL - I have answered you question with the resolution to your exception. Commented Jan 28, 2010 at 0:54
3

If you have .Net membership roles provider see this link first.

Some explanation since you said you did not understand

Net membership roles provider is setup to look for 'LocalSQLServer'. This means that we have to supply the details for a connection named LocalSQLServer or say it isnt needed. What you can do is in you web.config file find the <connectionstrings> part and add a line:

<add name='LocalSqlServer' connectionString='Data Source=DBServerName;
Integrated Security=false;Initial Catalog=DBName;
User ID=DBLogin;Password=DBPassword' providerName='System.Data.SqlClient' />

Replace the DBServerName with your SQL db server addon, DBName with the database name that came with your addon, DBLogin and Password should be replaced with what came with your SQL addon.

If you don't want to use LocalSQLSever you can remove it by

 <remove name='LocalSqlServer' />

in your web.config file under the properties. Then change the connection string name on your roles provider to the connection string name you will be using. So change your exisiting connection string to name='LocalSQLServer'.

Zhaph - Ben Duguid
27k5 gold badges87 silver badges123 bronze badges
answered Jan 20, 2010 at 10:28
6
  • thanks for that. it still doesnt work. I'm not sure what you mean about the "addon"? Commented Jan 20, 2010 at 11:32
  • 1
    Data Source=localhost for instance if you run your site on the machine where your DB is on. I think username and pw can be left out if you use standard windows login. Commented Jan 20, 2010 at 12:13
  • thanks for the reply. I've updated my question with stack-trace information. Commented Jan 20, 2010 at 12:21
  • 1
    Have a look down here since it seems to explain alot about what you are doing. odetocode.com/articles/428.aspx. Also have a look at part one. They explain about LocalSQLServer. I'm afraid, since im not completely familiar with asp.net 2.0 I cannot help you any further. Commented Jan 20, 2010 at 12:27
  • 1
    By the way, the error you get is because of wrong information in you connect string line, it cannot connect to your DB. Probably because you are using the standard DB which is not localhost. The information in the link above should give the correct connectionstring to use for the default settings. Commented Jan 20, 2010 at 12:42
0

It may be that you're getting a connection string from the machine.config. The easiest way to get rid of these, rather than using remove is to use a self closed clear element in the connectionstrings section.

The out of the box membership provider should have had a local connection string entry (new projects get this by default). You could create a new project and swipe it from there.

On the server you'll need to check SQL is installed correctly, and to update the connection string to match the server details.

answered Jan 29, 2010 at 23:36
0

I've often seen this message when the ASPNET user does not have read access to the config directory for the framework in question. It looks to me like you have a file directive in one of your keys, and the framework does not have access (either through permissions or because the file is not there) to read it.

answered Jan 29, 2010 at 23:39
0
Rob Hruska
121k32 gold badges169 silver badges192 bronze badges
answered Jan 28, 2010 at 18:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.