Results 1 to 10 of 10

Thread: [RESOLVED] Connection string in web.config problem.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Location
    Indiana
    Posts
    451

    Resolved [RESOLVED] Connection string in web.config problem.

    I am new to asp .net 2.0, and equally as new to web stuff in general. I am having a hard time understanding the whole web.config file stuff. I had an administrator page that worked fine in the root directory. However, I wanted to make a sub folder and use a web.config file to manage the role access. I did that, but now when I try to access the page it says it cannot connect to the SQL Server database. I am using the login control that comes with Visual Web Developer Express.

    I have been reading about the web.config files, and learned that the config file in the directory takes priority over the one in the parent directory. If this is true, how can I get the web.config file to read the connection string in the parent directory?

    I have tried the code below, but get:

    An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    This is a hosted SQL Server 2005 database, so I know it excepts remote connections. I can connect with files on my main directory.

    VB Code:
    1. <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    2.   <appSettings>
    3.         <connectionStrings>
    4.           <dataConfiguration defaultDatabase="PEPSqlServer"/>
    5.         </connectionStrings>
    6.   </appSettings>
    7.   <system.web>
    8.     <authentication mode="Forms" />
    9.         <authorization>
    10.             <allow roles="Director" />
    11.             <deny users="*" />
    12.             <deny users="?" />
    13.         </authorization>
    14.   </system.web>
    15. </configuration>

    Am I close?

  2. #2
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: Connection string in web.config problem.

    I'm not familiar with what your trying to do with the dataConfiguration node, but I always set my connection string like this

    VB Code:
    1. <appSettings>
    2.     <add key="ConnectionString"
    3.       value="server=localhost;database=Northwind;uid=sa;password=secret;" />
    4.   </appSettings>

    In the unlikely event that I answer your question correctly, please Rate my post

    Using Visual Studio 2005 Professional

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Connection string in web.config problem.

    The reason it works in the main web.config and not the child web.config is because you're probably missing more parameters in the child web.config.

    In .NET 2.0, to specify a connection string,

    Code:
    <connectionStrings>
            <add name="MyConnectionString"
                connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\YourDB.mdf;Integrated Security=True;User Instance=True"
                providerName="System.Data.SqlClient" />
        </connectionStrings>

    This is a copied example but the connection string would look either like this or something like drpcken has.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Location
    Indiana
    Posts
    451

    Re: Connection string in web.config problem.

    Thank you both for your help. I am not sure what that dataconfiguration node is supposed to do. I have been trying to figure out how to get this to work, and I saw that in another project somewhere else, and thought I would try it.

    I have spent some more time reading, and cleaning up the web.config file. The one in my main directory. This is what I have:

    VB Code:
    1. <?xml version="1.0"?>
    2. <!--
    3.     Note: As an alternative to hand editing this file you can use the
    4.     web admin tool to configure settings for your application. Use
    5.     the Website->Asp.Net Configuration option in Visual Studio.
    6.     A full list of settings and comments can be found in
    7.     machine.config.comments usually located in
    8.     \Windows\Microsoft.Net\Framework\v2.x\Config
    9. -->
    10. <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    11.   <appSettings>
    12.     <connectionStrings>
    13.       <add name="PEPSqlServer" connectionString="SERVER=sqlserver5.XXX.com;UID=XXXXXX;PWD=XXXXXX;Trusted_Connection=false;database=XXXXX" providerName="System.Data.SqlClient" />
    14.     </connectionStrings>
    15.     <add key="GoogleMerchantID" value="XXXXXXXX" />
    16.     <add key="GoogleMerchantKey" value="a1-XXXXXXXX" />
    17.     <add key="GoogleEnvironment" value="Sandbox" />
    18.   </appSettings>
    19.  
    20.   <system.web>
    21.     <membership defaultProvider="PEPProvider">
    22.       <providers>
    23.         <add name="PEPProvider"
    24.              connectionstringname="PEPSqlServer"
    25.              type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    26.              minRequiredPasswordLength="8"
    27.              minRequiredNonalphanumericCharacters="0"
    28.              applicationName="PEPWEB1"
    29.              enablePasswordRetrieval="false"
    30.              enablePasswordReset="true"
    31.              requiresQuestionAndAnswer="true"
    32.              passwordFormat="Hashed"
    33.              passwordStrengthRegularExpression="" />
    34.       </providers>
    35.     </membership>
    36.     <roleManager enabled="true"
    37.                  defaultProvider="PEPRoleProvider">
    38.       <providers>
    39.         <add name="PEPRoleProvider"
    40.              connectionStringName="PEPSqlServer"
    41.              applicationName="PEPWEB1"
    42.              type="System.Web.Security.SqlRoleProvider" />
    43.       </providers>
    44.     </roleManager>
    45.  
    46.     <!--
    47.             Set compilation debug="true" to insert debugging
    48.             symbols into the compiled page. Because this
    49.             affects performance, set this value to true only
    50.             during development.
    51.  
    52.             Visual Basic options:
    53.             Set strict="true" to disallow all data type conversions
    54.             where data loss can occur.
    55.             Set explicit="true" to force declaration of all variables.
    56.         -->
    57.     <pages>
    58.       <namespaces>
    59.         <clear/>
    60.         <add namespace="System"/>
    61.         <add namespace="System.Collections"/>
    62.         <add namespace="System.Collections.Specialized"/>
    63.         <add namespace="System.Configuration"/>
    64.         <add namespace="System.Text"/>
    65.         <add namespace="System.Text.RegularExpressions"/>
    66.         <add namespace="System.Web"/>
    67.         <add namespace="System.Web.Caching"/>
    68.         <add namespace="System.Web.SessionState"/>
    69.         <add namespace="System.Web.Security"/>
    70.         <add namespace="System.Web.Profile"/>
    71.         <add namespace="System.Web.UI"/>
    72.         <add namespace="System.Web.UI.WebControls"/>
    73.         <add namespace="System.Web.UI.WebControls.WebParts"/>
    74.         <add namespace="System.Web.UI.HtmlControls"/>
    75.       </namespaces>
    76.     </pages>
    77.     <!--
    78.             The <authentication> section enables configuration
    79.             of the security authentication mode used by
    80.             ASP.NET to identify an incoming user.
    81.         -->
    82.     <authentication mode="Forms">
    83.       <forms name=".PEPWEB1" />
    84.     </authentication>
    85.     <authorization>
    86.       <allow users="?"/>
    87.     </authorization>
    88.         <customErrors mode="Off"/>
    89.     </system.web>
    90. </configuration>

    But I get this error:

    The connection name 'PEPSqlServer' was not found in the applications configuration or the connection string is empty.

    on this line:

    Line 42: type="System.Web.Security.SqlRoleProvider" />


    I don't understand why it seems to recognize the connection string for the Membership Provider, but not the role provider.

    Again, thank you for helping me with this.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Location
    Indiana
    Posts
    451

    Re: Connection string in web.config problem.

    *bump

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Connection string in web.config problem.

    Try

    connectionstringname -> connectionStringName

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Location
    Indiana
    Posts
    451

    Re: Connection string in web.config problem.

    Thank you for pointing that out. However, it didn't solve the problem. Same problem, same line. I am at a loss. Thank you for your help. Any more ideas?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Location
    Indiana
    Posts
    451

    Re: Connection string in web.config problem.

    Ok, I changed PEPSqlServer with LocalSqlServer and the page now loads. Does this mean that I am now allowed to name my own connections strings?

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Location
    Indiana
    Posts
    451

    Re: Connection string in web.config problem.

    I spoke too soon. The page displays, but I can't log in. It says it can't connect to the SQL Server.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Location
    Indiana
    Posts
    451

    Re: Connection string in web.config problem.

    I got it figured out. I had the connection string inside the <appSettings> area. I removed them. Made everything uniform, and it works.

    Thank you for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width