Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 15, 2012 09:43 AM by Decker Dong - MSFT
Dec 14, 2012 09:58 PM|LINK
Any opinions on these questions are appreciated:
1. I have a DatabaseManager class where I determine my connection string based on the domain authority like this:
string s = HttpContext.Current.Request.Url.Authority;
For example, If I'm working on my development machine, the static constructor would look for "localhost" in the url and set the connection string accordingly. Is there a better way to automatically figure out the connection string value?
2. For all of my Select commands, I have a public method that I call that lives in the DatabaseManager class:
public static DataSet DoGenericSelect(string pSelectCommand)
using (DataSet ds = new DataSet())
using (SqlDataAdapter da = new SqlDataAdapter(@pSelectCommand, connectionString))
Question here is: Am I using the using statement correctly, resources being disposed properly? Can this be improved?
3. This is the method I am worrying about the most:
public static int DoGenericBulkTableUpdate(DataTable pDataTable, string @pSql)
using (SqlConnection conn = new SqlConnection(connectionString))
var dataTableFromDatabase = new DataTable();
var cmd = new SqlCommand(@pSql, conn);
var da = new SqlDataAdapter(cmd);
var cb = new SqlCommandBuilder(da);
da.UpdateCommand = cb.GetUpdateCommand();
Do I need more Using statements to make sure I am disposing the SqlCommand, DataAdapter, etc properly?
Dec 14, 2012 10:44 PM|LINK
You should use using with Unmanaged Code.
You don't need more but if there's more unmanaged code you should have more nest using.
Dec 15, 2012 01:13 AM|LINK
Dec 15, 2012 09:43 AM|LINK
We suggest you speaking "Thanks" for "danke" in English, for this is an English forum;)