c# - Simplest way to create database from connection string? -


we're looking hands-on way create database given connection string minimum code possible (e.g., include in linqpad scripts or c# scriptlets).

is there one-liner or similar create database connection string? preferably "static.createdatabase("connection string").

i have created static class scripts contains static method createdatabase

// use class scripts.createdatabase("connectionstring")  //class static class scripts     {          static bool createdatabase(string connectionstr)         {             bool result =false;                sqlconnection conn = new sqlconnection(connectionstr); // pass connection string , user must have permission create database,                string query = "create database exampledatabase ";                 sqlcommand command = new sqlcommand(query, conn);                 try                 {                     conn .open();                     command.executenonquery();                     result =true;                 }                 catch (system.exception ex)                 {                     result =false;                 }                                 {                     if (conn.state == connectionstate.open)                     {                         conn.close();                     }                 }             return result;         }      } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -