I am trying to create database,schema and tables through c# code and so far i have successfully created database but getting error while creating schema:
I am trying to create below schema:
1) Person
2) Production
3) Sales
4) dbo
Now some tables have schema as Person and some tables have schema as dbo and so while creating tables i would like that tables to have appropriate schema.
I am not getting error while creating Person,Production and sales schema but i get error while creating schema for dbo.
Error:The specified schema name "dbo" either does not exist or you do not have permission to use it.CREATE SCHEMA failed due to previous errors.
Code: This is my code:
conn.Open();
foreach (var item in schemaList)
{
sqlQuery = "CREATE SCHEMA " + schema;
using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
{
cmd.CommandTimeout = 0;
cmd.ExecuteNonQuery();
}
}
conn.Close();
Why does this permission problems doesnt comes in case of creating other schema and why it comes only while creating dbo schema.

dboschema (and several others) always exists in any database. As such, it can't be created.