Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5965549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:38:48+00:00 2026-05-22T19:38:48+00:00

Note: I DON’t want to write custom membership provider. I want to write my

  • 0

Note: I DON’t want to write custom membership provider.

I want to write my own Provider class so I can define it in web.config and access it like Membership class.

Here is a sample of my class (it has many other static methods):

public static class MySqlHelper
{
    private static string constring = ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString;

    public static int ExecuteNonQuery(string mysqlquery)
    {
        SqlConnection conn = new SqlConnection(connString);
    SqlCommand cmd = new SqlCommand(mysqlquery, conn);
    int result;

    try
    {
        conn.Open();
        result= cmd.ExecuteNonQuery();
    }
    finally
    {
        conn.Close();
    }
    return result;

    }
}

Usage: MySqlHelper.ExecuteNonQuery("select * from customers");

Now as you see I have hard-coded the name of connectionstring i.e. “MyConnString”. I am planning to make it dynamic.

So I was wondering if I can make it like static built-in Membership class, where I can define the connectionStringName in web.config. This way the class can be made re-usable without always naming my connectionstring in web.config to “MyConnString”.

1: I DON’T want to pass connectionstring in every static method as a parameter.

2: I must be able to access the methods similar to Membership.CreateUser i.e. static.

I am looking over the web in parallel but any inputs/guidance will help.

Edited: I have updated my code sample, to clear some confusion about issues using static class. Here is a new question I posted to clarify that. Sorry about confusion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:38:50+00:00Added an answer on May 22, 2026 at 7:38 pm

    the only thing i can think of that meets the qualifications you laid out is to use dependency injection, a static constructor, and inject in an something like an IConnectionStringProvider. this seems like about the most convoluted thing i can think of, so you might like it. 🙂

    edit

    after reading your comment, it seems like you just want to be able to reference any connection string, but only one connection string per application. i’d say just add an element to appSettings named MySqlProviderConnection with the value being the name of the connection string you want to use.

    then in your helper, check for the existence of the appsetting, get its value, and pass it in to your ConfigurationManager.ConnectionStrings call. that way your provider could use any connection you want, without changing any code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please note: I don't want to resize my own page, just the browser window,
Note: I don't want to attach the Image to the Email I want to
NOTE: I'm ultra-newbie on algorithm analysis so don't take any of my affirmations as
Please note that I'm not asking how but why. And I don't know if
I am reading the Java Hashmap documentation but I don't understand this sentence. Note
note: i only want to move 1 shape at a time Circle.prototype.create = function(){
Note: I don't do .NET programming regularly. Normally I do native/MFC, so I'm a
Note:I don't mean some theoretical question which don't have any implementation just languages that
How to show two fieldsets horizontally in a form? Note: I don't mean show
So what I want is to have a html text field where someone can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.