Solved

Errors in ASP.NET machine.config and web.config

Posted on 2008-10-03
10
1,319 Views
Last Modified: 2008-10-05
Hi,

I recently put my site on the servers of a web hosting service.
The site included an SqlServer Express database named "Pictures"  and the remote database serve is called dbs5.dailyrazor.com.
The Welcome page has a link that sends me to a Login page... but once I log in I get the following error message:

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:

Line 137:    <membership>
Line 138:      <providers>
Line 139:        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
Line 140:      </providers>
Line 141:    </membership>


Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Config\machine.config    Line: 139

------------------
The problem is that I located the error in the machine.config and changed the connection name to dbs5.dailyrazor.com
I also searched my web.config file and made sure there was no mention of "locaSqllServer", yet I keep getting the same message after going so far as to replace all the files on the remote server with the updated files on my machine.
I am attaching the connectionString that I have in my web.config:


 
<connectionStrings>

    <clear/>

    <add name="Pictures" connectionString="Server=dbs5.dailyrazor.com;Database=Pictures;Persist Security Info=True;User ID=myUserName;Password=myPassword"

   providerName="System.Data.SqlClient"/>

    <remove name="dbs5.dailyrazor.com"/>

    <add name="dbs5.dailyrazor.com" connectionString="dbs5.dailyrazor.com; Database=Pictures;Persist Security Info=True;User ID=myUserName;Password=myPassword" providerName="System.Data.SqlClient"/>

  </connectionStrings>

Open in new window

0
Comment
Question by:tariqanis
  • 5
  • 5
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Why are you using machine.config to store a connection string? You have no access to machine.config on a shared server. You should use the web.config to store this connection string.
0
 

Author Comment

by:tariqanis
Comment Utility
I did not put machine.config onthe remote server, but the error cites machine.config..... I don't know how it got on the remote server when I don't see it in my application......
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
The error is generic then as the asp.net looks for web.config and then for machine.config. Try to use correct connection strings and names in the web.config
0
 

Author Comment

by:tariqanis
Comment Utility
The first time I opened  machine.config  was when I saw that error message which says that the error is in machine config.....

I thought that maybe it gets copied automatically with the rest of the application when I use the Copy Web Site utility that comes with ASP.NET.... And I don't see machine.config in the Solution Explorer, so I really don't understand how it was copied to the remote server!! In fact I don't see it on the remote server with the rest of my files... there is only a web.config.

By the way I am using Microsot Visual Studio Professional 3.5....
0
 

Author Comment

by:tariqanis
Comment Utility
Do you see any thing wrong in the connectionString cited above?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Machine.config is not copied with your website. It is installed by default along with the .NET framework.
I dont see anything wrong with this connectionstring except that i am not sure about the <clear /> tag. Remove that tag. How are you using the connectionstring in the code?
0
 

Author Comment

by:tariqanis
Comment Utility
Only in some files do I use the database. The attachedcode is used each time I need to retrieve data from the database:
 
Dim connectionString As String = _

ConfigurationManager.ConnectionStrings("Pictures").ConnectionString

        Dim con As New SqlConnection(connectionString)

        Dim commTariq As SqlCommand

        Dim reader As SqlDataReader

        commTariq = New SqlCommand("Select Caption from Pics where Name='" & myTextBox.Text.ToString & "'", con)

        Try

            ' Open Connection

            con.Open()

            ' reader read command

            reader = commTariq.ExecuteReader()

            ' Display the requested data

            If reader.Read() Then

                captionLabel.Text = reader.Item("Caption")

            Else

                captionLabel.Text = "No text found"
 

            End If
 

            ' Close dataReader

            reader.Close()
 

        Finally

            ' close connection

            con.Close()

        End Try

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
everything seems ok with the code.
0
 

Author Comment

by:tariqanis
Comment Utility
Well, I deleted the <Clear/> tag and now have 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)


0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
Now you need to make sure that the connectionstring is valid according to the SQL Server configuration you have. Verify that the server name, instance name, and database names are valid and that the SQL Server does allow remote connections.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now