I am trying to connect to SQL Server 2005 Express with Visual C# 2005
Express using this code:
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\temp.MDF;User
ID=MyUsername;password=MyPass;DATABASE=Test;Integr ated
Security=False;User Instance=True");
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=|DataDirector y|\temp.MDF;User
ID=MyUsername;password=MyPass;DATABASE=Test;Integr ated
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