using System;
using System.Threading;
using System.Data;
using System.Data.SqlClient;
namespace DBUtility
{
public static class ConnectionManager
{
private static LocalDataStoreSlot LocalDataStoreSlot = null;
public static SqlConnection Connection(string connstring)
{
if (LocalDataStoreSlot == null)
LocalDataStoreSlot = Thread.AllocateDataSlot();
SqlConnection conn = Thread.GetData(LocalDataStoreSlot) as SqlConnection;
if (conn == null)
{
conn = new SqlConnection(connstring);
}
else
{
Thread.SetData(LocalDataStoreSlot, conn);
}
return conn;
}
}
}
浙公网安备 33010602011771号