Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use SQL from asp.net?
    text
    copied!<p>Building a relatively simple website, and need to store some data in the database (mainly authentication, but there's some per-user stuff). I've worked on a couple of websites previously, and used database there too, but never liked the way I accessed the database.</p> <p>The way I usually did this was by having a SqlMethods.cs, which basically was a static class with a whole lot of static methods such as <code>bool CheckUserExistence(string username, string password)</code> and <code>SqlDataReader GetJobListings(int advertiserId)</code>, each of which was essentially "open connection, call a sproc, return what it returns". This approach seems un-natural to me, however. I cant quite put my mind to what I want it to look like, but this seems...weird.</p> <p>So, my question is this: how do you access the database from your asp.net projects?<br> I am using SQL2005. I also dont think I'll need an ORM of any kind, since there really isnt that much to get from the DB, but maybe its easier with one? Suggest something. Thanks!</p> <p><em>Edit</em>:I currently decided to just create a static class <code>Sql</code> that will have a number of sql-related methods (such as <code>ExecuteReader(sprocName, params[])</code>, etc) that will call the sproc with the given parameters and just return the DataReader.<br> Then, have classes for specific functionality, such as <code>Authentication</code> with methods like <code>CheckUserExistence(username, password)</code> and <code>LogoffUser(session)</code>. These methods would just call <code>Sql.ExecuteReader("sp_Auth_CheckUserExistence", _some_params_here_)</code> and process the result as needed.<br> I don't know if thats good or bad, but it seems to work for me at the moment. Plus, I like the way it feels - its all nicely separated functionality-wise.</p> <p>So, any more suggestions?</p>
 

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