use using keyword to connect to database.
using System.Data;
using System.Data.SqlClient;
String conString = "Data Source=SERVER;UID=user;PWD=passsword Integrated Security=True;";
using (SqlConnection sqlCon = new SqlConnection (conString))
{
sqlCon.Open();
DataTable tblDatabases = sqlCon.GetSchema ("Databases");
sqlCon.Close();
foreach (DataRow row in tblDatabases.Rows)
{
Console.WriteLine ("Database: " + row["database_name"]);
}
}
No comments:
Post a Comment