conn.Open();
conn.Close();
}
I get an error while calling the method Open Here is the error
"Failed to generate a user instance of SQL Server. Only an integrated
connection can generate a user instance. The connection will be
closed."
so I changed the connection string to
SqlConnection conn = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\temp.MDF;User
ID=MyUsername;password=MyPass;DATABASE=Test;Integrated
Security=False;User Instance=False");
and I get error when while calling Open:
"Database 'c:\\Program Files\\Microsoft SQL
Server\\MSSQL.1\\MSSQL\\DATA\\test.mdf' already exists.\r\nCould not
attach file 'C:\\Projects\\test1\\test\\bin\\Debug\\temp.MDF' as
database 'Test'."
The user account MyUsername has is part of Server Role sysadmin.
I can also connect to this database using Microsoft SQL Server
Management Studio Express without a problem with the same user.
So does anyone know what i'm doing wrong?
Thanks,
BravesCharm
http://msdn2.microsoft.com/en-us/library/ms254504
http://www.connectionstrings.com/
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"BravesCharm" <mastr...@gmail.com> wrote in message
news:1131808156.2...@g44g2000cwa.googlegroups.com...
SqlConnection conn = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\test.MDF;User
ID=MyUsername;Password=MyPast;Integrated Security=False;User
Instance=False");
conn.Open();
and it still doesn't work! I get the error:
An attempt to attach an auto-named database for file
C:\\Projects\\test1\\test\\bin\\Debug\\test.MDF failed. A database with
the same name exists, or specified file cannot be opened, or it is
located on UNC share.
I also tried:
SqlConnection conn = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\test.MDF;User
ID=MyUsername;Password=MyPast;Initial Catalog=Test;Integrated
Security=False;User Instance=False");
conn.Open();
and got the same error
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;User
ID=MyUsername;Password=MyPassword;Initial Catalog=Test;Integrated
Security=False;User Instance=False");
conn.Open();
However, I still can't seem to connect using AttachDbFilename and I
also can't seem to connect using Database Explorer(which I believe uses
AttachDbFilename). The connection strings I've used are:
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;User
ID=MyUsername;Password=MyPassword;AttachDbFilename=|DataDirectory|\test.mdf;DATABASE=Test;Integrated
Security=False;User Instance=False");
and
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;User
ID=MyUsername;Password=MyPassword;AttachDbFilename=|DataDirectory|\test.mdf;Integrated
Security=False;User Instance=False");
and both times I get the error:
An attempt to attach an auto-named database for file
C:\\Projects\\test1\\test\\bin\\Debug\\test.mdf failed. A database with
the same name exists, or specified file cannot be opened, or it is
located on UNC share."
Anyone know what I'm doing wrong?
So it worked when I did:
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;User
ID=MyUsername;Password=MyPassword;Initial Catalog=Test;Integrated
Security=False;User Instance=False");
conn.Open();
Or
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;User
ID=MyUsername;Password=MyPassword;Database=Test;Integrated