Solved

connectionStringName

Posted on 2007-11-29
8
386 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

13 Experts available now in Live!

Get 1:1 Help Now