Hi,
You can set up the SQL database connection by taking as main data connection for your InfoPath form to submit the data to a database. And you can set up the SQL database connection as secondary data connection to receive the data from a database. And you can submit the data using rules with out using managed code.
If you want to submit the data using managed code use the dataadapters as given below in onSubmitRequest event.
function XDocument::OnSubmitRequest(eventObj)
{
var submitAdapter = XDocument.DataAdapters("Main submit");
submitAdapter.Submit();
eventObj.ReturnStatus = true;
}
You can get the similer instructions in the given below link to set up a database connection( but it includes the example by using access db instead of sql)
http://office.microsoft.com/en-us/assistance/HA011199501033.aspx
I hope, it will help you.