If the connection is open before the Fill() method is called, then no, the connection will not be closed by the DataAdapter.
However, if you do not explicitly open the connection, and instead let the DataAdapter open and close the connection within the Fill() command, then the connection will be closed on error.
This can be implied from multiple sources of documentation, including this one: Data Access Strategies Using ADO.NET and SQL
Further, this can be demonstrated in code by writing a routine that will error out and then checking the connection's State.
This code from a Windows Forms app proves it. The first message box will say "Open" and the second "Closed".
string connString = "";
private void Form1_Load(object sender, EventArgs e)
{
connString = Properties.Settings.Default.EventLoggingConnectionString;
ExplicitlyOpenConnection();
LetDataAdapterHandleIt();
}
private void ExplicitlyOpenConnection()
{
System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(connString);
System.Data.DataSet ds = new DataSet();
System.Data.SqlClient.SqlDataAdapter ad = new System.Data.SqlClient.SqlDataAdapter("Select bogusdata from nonexistenttable", cn);
cn.Open();
try
{
ad.Fill(ds);
}
catch (Exception ex)
{
}
MessageBox.Show(cn.State.ToString());
cn.Close();
}
private void LetDataAdapterHandleIt()
{
System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(connString);
System.Data.DataSet ds = new DataSet();
System.Data.SqlClient.SqlDataAdapter ad = new System.Data.SqlClient.SqlDataAdapter("Select bogusdata from nonexistenttable", cn);
try
{
ad.Fill(ds);
}
catch (Exception ex)
{
}
MessageBox.Show(cn.State.ToString());
}