I'm not sure how you'd do it from scratch. What I do is include a blank database file as a resource with a specific password. Then, I just write that blank database to the file location and alter the database password. My code looks like:
<System.Diagnostics.DebuggerStepThrough()> _
Public Function CreateDatabase(ByVal Path As String) As String
Dim password As String = ""
Dim newPasswordEntry As New PasswordEntry()
newPasswordEntry.ShowDialog()
newPasswordEntry.Focus()
If newPasswordEntry.result = Windows.Forms.DialogResult.OK Then
password = newPasswordEntry.value
Else
Return ""
End If
Try
File.WriteAllBytes(Path, My.Resources.RecoveryPlanDB_BE_Master)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dim cn As New OleDbConnection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path & _
";Jet OLEDB:Database Password=password;" & _
"Mode=Share Deny Read|Share Deny Write;"
cn.Open()
Dim cmd As New OleDbCommand
cmd.Connection = cn
cmd.CommandText = "ALTER DATABASE PASSWORD [" & password & "][password]"
cmd.ExecuteNonQuery()
cn.Close()
cmd.Dispose()
cn.Dispose()
Return password
End Function
Of course, that's VB, so you'd have to change a bit (especially the accessing the file in the resources), but that's the idea.