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?

  • So are you trying to connect to MS Sql Server or by tagging a question from MySQL ? - Bulson
  • I'm trying to create a local database, maybe I made a mistake in the tag - Walker
  • you have in item 5 of your manual Введите в строку подключения значение для используемого SQL Server - did you do it? - tym32167
  • 2
    First, remember: MySql and SqlServer are completely different DBMSs. Do not confuse them! | Did you install a separate version of Sql Server on your computer? Surely not. Therefore, LocalDB is used, which is installed instead of with Visual Studio. For it, the connection string should be (localdb)\MSSQLLocalDB instead of localhost (this is what tym32167 meant). - Alexander Petrov

0