Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting my own Provider Class in ASP.NET
    primarykey
    data
    text
    <p>Note: I DON't want to write custom membership provider.</p> <p>I want to write my own Provider class so I can define it in web.config and access it like Membership class.</p> <p>Here is a sample of my class (it has many other static methods):</p> <pre><code>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; } } </code></pre> <p>Usage: <code>MySqlHelper.ExecuteNonQuery("select * from customers");</code></p> <p>Now as you see I have hard-coded the name of connectionstring i.e. "MyConnString". I am planning to make it dynamic.</p> <p>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".</p> <p>1: I DON'T want to pass connectionstring in every static method as a parameter.</p> <p>2: I must be able to access the methods similar to Membership.CreateUser i.e. static.</p> <p>I am looking over the web in parallel but any inputs/guidance will help.</p> <p><strong>Edited:</strong> I have updated my code sample, to clear some confusion about issues using static class. Here is a <a href="https://stackoverflow.com/questions/6156107/what-are-the-potential-issues-using-this-static-class">new question</a> I posted to clarify that. Sorry about confusion.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload