An attempt to attach an auto-named database for file C:\Documents and Settings\John Khalil\Desktop\s.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
here the code to create the database
Expand|Select|Wrap|Line Numbers
- SqlConnection temp = new SqlConnection(@"Data Source=.\SQLEXPRESS;Database = master;Integrated Security=True;Connect Timeout=30;User Instance=True");
- string query = string.Format(" CREATE DATABASE "
- + name
- + " ON PRIMARY "
- + " (NAME = " + name +", "
- + " FILENAME = '" + path +"', "
- + "User ID = " + user
- + "Password =" +pass
- +")");
- SqlCommand command = new SqlCommand(query, temp);