I use the code from https://support.microsoft.com/ru-ru/help/307283/how-to-create-a-sql-server-database-programmatically-by-using-ado-net
the result is such a method
public static void CreativBace(long id) { String str; SqlConnection myConn = new SqlConnection("Server=(localdb)\MSSQLLocalDB;Integrated security=SSPI;database=master"); str = "CREATE DATABASE MyDatabase ON PRIMARY " + "(NAME = MyDatabase_Data, " + "FILENAME = '"+Form1.pathBase+"\\"+ id + ".mdf', " + "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " + "LOG ON (NAME = "+id+ "_log.ldf," + "FILENAME = '"+Form1.PathData+"\\"+ id + ".ldf', " + "SIZE = 1MB, " + "MAXSIZE = 5MB, " + "FILEGROWTH = 10%)"; SqlCommand myCommand = new SqlCommand(str, myConn); //try //{ myConn.Open(); myCommand.ExecuteNonQuery(); MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information); //} //catch (System.Exception ex) //{ //MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information); //} //finally //{ if (myConn.State == ConnectionState.Open) { myConn.Close(); } //} } but gives an error
Invalid usage of the option _log in the CREATE / ALTER DATABASE statement. "How to fix?
MS Sql Serveror by tagging a question fromMySQL? - BulsonВведите в строку подключения значение для используемого SQL Server- did you do it? - tym32167(localdb)\MSSQLLocalDBinstead oflocalhost(this is what tym32167 meant). - Alexander Petrov