Yes.
Although SqlConnection objects are scarce resources, provided that you Dispose of them when you have finished, you can create as many as you need. The simplest way is to enclose them in a
using
block:
using (SqlConnection con = new SqlConnection(strConnectFirstDB))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("...", con))
{
...
}
}
using (SqlConnection con = new SqlConnection(strConnectOtherDB))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("...", con))
{
...
}
}
Or
using (SqlConnection con = new SqlConnection(strConnectFirstDB))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("...", con))
{
using (SqlConnection con = new SqlConnection(strConnectOtherDB))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("...", con))
{
...
}
}
}
}
Either will work fine