Link to home
Start Free TrialLog in
Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Why do I need a connectionstring called LocalSQL Server?

I have about 8 web based GUIs.
My web.config file has 4 connection strings depending on which site the user logs into (dev, QA, production or disaster recovery).
The program looks at C:\inetpub\wwwroot\win.config to find out which site the user has logged into.

I’ve done this for my GUIs.  Most of them authenticate by checking if the user’s TEN ID is in web.config.  However, I have one GUI where the user must enter their name and a password that they choose.
I get an error message because there is no connection string named LocalSQLserver.
Since I have 4 connection strings (dev, qa, prod and DR), I deliberately made sure that none were called LocalSQLServer, so I could be sure that my GUI was connecting to the correct database.
Did you have a problem like this?  If so, how did you get round it?
I know that localSQLServer appears in C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.config, but I don’t see why that matters.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

you may try to read this:

ASP.NET Configuration File Hierarchy and Inheritance
https://msdn.microsoft.com/en-us/library/ms178685.aspx

to resolve your issue, remove the relevant connectionstring setting from C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.config
Avatar of AlHal2

ASKER

It looks like the login control is calling the stored procedure aspnet_CheckSchemaVersion on localsqlserver.  What will it do if I amend machine.config?
Is it possible to amend the login control instead?

I'm worried about other applications being affected.
Avatar of AlHal2

ASKER

I tried amending machine.config to test things, but was told that access has been denied.
Is there a way to amend the login control to look at the db that I specify in my web.config file for this application?

What were these lines supposed to achieve?

<connectionStrings>
            <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
      </connectionStrings>
you can open the  C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\Machine.config

and check the connectionstring for LocalSqlServer, see if it's pointing to a default database.

if it's pointg to |DataDirectory|aspnetdb.mdf and you're not using it, you can remark the line and reboot your IIS for testing.
>>Is there a way to amend the login control to look at the db that I specify in my web.config file for this application?
you need to open the file with Administrator right or perhaps your IIS services is not running.
>>What were these lines supposed to achieve?

Contains application data files including MDF files, XML files, as well as other data store files. The App_Data folder is used by ASP.NET 2.0 to store an application's local database, which can be used for maintaining membership and role information. For more information, see Introduction to Membership and Understanding Role Management.

https://msdn.microsoft.com/en-us/library/ex526337(v=vs.100).aspx
Avatar of AlHal2

ASKER

>>Is there a way to amend the login control to look at the db that I specify in my web.config file for this application?
 you need to open the file with Administrator right or perhaps your IIS services is not running.
Thanks for this.  Are you referring to the file machine.config?

I was wondering if there is a property of the login control that can be changed.  This would stop me having to change machine.config.
>>Are you referring to the file machine.config?
Yes

>>I was wondering if there is a property of the login control that can be changed.  This would stop me having to change machine.config.
Alternatively, look for Configuration Editor in your IIS panel

and then select the connectionStrings from the dropdown list.

You should see Collection Count = 1. click on the "..." button to proceed to remove.

User generated image
Avatar of AlHal2

ASKER

I removed the connection string using IIS and got this error after I pressed login in the login control.

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.


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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +6299673
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean withFailover) +536
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject, Boolean withFailover) +283
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +6319714
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +6319672
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +354
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +300
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +45
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +6324046
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6324359
   System.Data.SqlClient.SqlConnection.Open() +258
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +115

[HttpException (0x80004005): Unable to connect to SQL Server database.]
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +4041989
   System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +159
   System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +825
so are you using a local Sql Server Express instance using a database location within the applications App_Data directory? if yes you shouldn't removed that...
Avatar of AlHal2

ASKER

How can I find out if I'm using a local Sql Server Express instance using a database location within the applications App_Data directory?
The App_data directory is empty.
sorry that generally out of my knowledge as I didn't use App_data directory for application development.

but just think that that's some dependencies within your 8 web based GUIs.
Avatar of AlHal2

ASKER

No problem.
Last question (I hope).  Is it possible to see the coding behind the login control?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlHal2

ASKER

Thanks.