Solved

connectionStringName

Posted on 2007-11-29
8
390 Views
Last Modified: 2011-09-20
Can I use the connectionStringName of the existing connection string from my weg.config file within my custom membershipprovider setup?

If so, any reason why it's not working? when I do?

    <membership defaultProvider="CMembershipProvider">
      <providers>
        <clear/>
        <add name="CMembershipProvider" type="CMembershipProvider" requiresQuestionAndAnswer="false" enablePasswordRetrieval="true" enablePasswordReset="true"
             description="Custom: Membership Provider: Stores and retrieves membership data from SQL Server"
             requiresUniqueEmail="true" applicationName="/" passwordFormat="clear"
             userIsOnlineTimeWindow="15"
             connectionString="Data Source=xx.xx.xx.xx;Initial Catalog=xxxX;Integrated Security=True"/>
      </providers>
    </membership>
0
Comment
Question by:Starr Duskk
[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
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:anoyes
ID: 20380254
Is there an error you're getting?  In your web.config you have to have a connectionString item, for example:

<connectionStrings>
  <clear />
  <add name="MyConnection"
      connectionString="Data Source=xx.xx.xx.xx;Initial Catalog=xxxX;Integrated Security=True"
      providerName="System.Data.SqlClient" />
</connectionStrings>

as well as a section for you membershipprovider, which you have shown above.  In your example above, however, you have not specified a connectionStringName.  In this case, it should be "MyConnection", so your MembershipProvider section would end up looking like:
<membership defaultProvider="CMembershipProvider">
      <providers>
        <clear/>
        <add name="CMembershipProvider" type="CMembershipProvider"
             requiresQuestionAndAnswer="false" enablePasswordRetrieval="true"
             enablePasswordReset="true" description="Custom: Membership Provider: Stores and retrieves
             membership data from SQL Server" requiresUniqueEmail="true" applicationName="/"
             passwordFormat="clear" userIsOnlineTimeWindow="15"
             connectionStringName="MyConnection" />
      </providers>
    </membership>
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 20380379
yes, I define the connection string at the top in the connection strings.

Then I use it as a connectionStringName within my role provider. But when I attempt to use it as a name in my membershp provider, it fails. Won't let me log in to my custom sql provider.

0
 
LVL 16

Expert Comment

by:anoyes
ID: 20384891
Do you get an error message?  Any by log in to your custom sql provider, do you mean that when you try to log into the site it won't validate?  I would venture to guess that if it works with the role provider and not the membership provider, then it's probably a problem w/ the custom provider.
0
Revamp Your Training Process

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

 
LVL 2

Author Comment

by:Starr Duskk
ID: 20385220
No, I don't get an error message. But when I log in using the Membershipprovider, if I have the connectionString, it works fine, if I use the connectionStringName, it fails on the log in. I stpped through the code and on the conn.Open() it throws an exception....

"the connection string property has not been initialized."

I guess, if I stop to think about it, I don't "know" for a fact if the connectionstringName is working right in the roleprovider as I haven't technically used it yet.

here is my connection string:
  <connectionStrings>
    <add name="xxConnectionString" connectionString="Data Source=xx.xx.xx.xx;Initial Catalog=xxX;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>

here is how it is defined in the provider (which works)
connectionString="Data Source=xx.xx.xx.xx;Initial Catalog=xxX;Integrated Security=True"

for the name, when I use a provider it is like so:
  connectionStringName="xxConnectionString"

(if I have typos from XXing things out, they are likely just typos).

But bottom line is that I have manually pasted the string from the original string for the provider, so it seems the name should work.

0
 
LVL 16

Expert Comment

by:anoyes
ID: 20386867
Let's take a look at the code in your custom MembershipProvider that gets the connection string from the config file.  How are you going about getting the connection info now in the provider?
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 20396315
I have this at the top:
Imports System.Data
Imports System.Data.SqlClient

this in the class:
    Private connStr As String
    Private comm As New SqlClient.SqlCommand

this in my initialize (I've tried both):
        connStr = config("connectionStringName")
or this:
        connStr = config("connectionString")

and this in the method:
    Public Overrides Function ValidateUser(ByVal username As String, ByVal password As String) As Boolean

        Using conn As New SqlConnection(connStr)
            Try
                conn.Open()

this in the web.config for the provider, with XXConnectionString being the one defined previously:
connectionStringName="XXConnectionString"

The error with connStr = config("connectionStringName") is:
Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
Using conn As New SqlConnection(connStr)
0
 
LVL 16

Accepted Solution

by:
anoyes earned 500 total points
ID: 20405753
After some researching what I've found is that config("connectionStringName") is actually only the value of connectionStringName; in this case xxConnectionString.  You have to go one step further and go and get the actual connection string that is associated with that name.

connStr = ConfigurationManager.ConnectionStrings(config("connectionStringName")).ConnectionString

See if that works.
0
 
LVL 2

Author Closing Comment

by:Starr Duskk
ID: 31411842
Perfect. You are so very smart. :)
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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