Solved

connectionStringName

Posted on 2007-11-29
8
389 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Securing WEBAPI on Azure 2 27
Consume a webservice via VB in Visual Studio 2015 3 22
Aspx calendar pop up control 3 28
Connect Gridview column to Textbox in C# 2 41
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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 …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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