By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

createing database problem

P: 26
Dear all while I am trying to create database..I got these error

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
  1. SqlConnection temp = new SqlConnection(@"Data Source=.\SQLEXPRESS;Database = master;Integrated Security=True;Connect Timeout=30;User Instance=True");
  2.  
  3.             string query = string.Format(" CREATE DATABASE "
  4.                        + name
  5.                        + " ON PRIMARY " 
  6.                        + " (NAME = " + name +", "
  7.                        + " FILENAME = '" + path +"', " 
  8.                        + "User ID = " + user
  9.                        + "Password =" +pass
  10.                        +")");
  11.             SqlCommand command = new SqlCommand(query, temp);
  12.  
any idea?
Mar 9 '09 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
Well, is it already existing?

-- CK
Mar 10 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.