Solved

Why do I need a connectionstring called LocalSQL Server?

Posted on 2016-07-21
15
43 Views
Last Modified: 2016-07-25
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.
0
Comment
Question by:AlHal2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41723959
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
0
 

Author Comment

by:AlHal2
ID: 41724234
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.
0
 

Author Comment

by:AlHal2
ID: 41724267
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>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41724273
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.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41724276
>>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.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41724279
>>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
0
 

Author Comment

by:AlHal2
ID: 41724403
>>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.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41724413
>>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.

SnapShot.png
0
 

Author Comment

by:AlHal2
ID: 41724456
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
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41724460
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...
0
 

Author Comment

by:AlHal2
ID: 41724469
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.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41727431
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.
0
 

Author Comment

by:AlHal2
ID: 41727435
No problem.
Last question (I hope).  Is it possible to see the coding behind the login control?
0
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41727446
>>Is it possible to see the coding behind the login control
yes you can. you can always debugging at code behind. but if you mean to use controls like Login, you can only customize it via the VS properties interface or convert them to template for custom editing.
SnapShot.png
0
 

Author Closing Comment

by:AlHal2
ID: 41727717
Thanks.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Multi-Column Repeater 3 39
Adjust the codes 3 65
history of pages 7 55
What is needed to become a DBA? 7 56
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question