المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Best way to access a database



C# Programming
05-03-2010, 01:43 AM
I dont want to have to type this out every time I want to connect to the database. Can I put this in a class or something?

What would be the best way to do this so I can call myConnection from anywhere inside my application?


SqlConnection myConnection = new SqlConnection("user id=username;" +
"password=password;server=serverurl;" +
"Trusted_Connection=yes;" +
"database=database; " +
"connection timeout=30");

Thanks in advanced as I am pretty much learning.