Solved

connectionStringName

Posted on 2007-11-29
8
388 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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