Solved

connectionStringName

Posted on 2007-11-29
8
384 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:BobCSD
  • 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 1

Author Comment

by:BobCSD
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
 
LVL 1

Author Comment

by:BobCSD
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 1

Author Comment

by:BobCSD
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 1

Author Closing Comment

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

19 Experts available now in Live!

Get 1:1 Help Now