// If the connection string is null, use a default.
if(myConnectionString == "")
{
myConnectionString = "Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;";
}
SqlConnection myConnection = new SqlConnection(myConnectionString);
string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
SqlCommand myCommand = new SqlCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
这是MSDN的帮助,这样的话,每次都要一个 new SqlConnection(myConnectionString),这样是不是就没有连接池的概念?每一个动作就一次连接?
if(myConnectionString == "")
{
myConnectionString = "Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;";
}
SqlConnection myConnection = new SqlConnection(myConnectionString);
string myInsertQuery = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')";
SqlCommand myCommand = new SqlCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
这是MSDN的帮助,这样的话,每次都要一个 new SqlConnection(myConnectionString),这样是不是就没有连接池的概念?每一个动作就一次连接?
--就是说我操作数据库时只管new connection就是了,但不要调用dispose()方法?