I have been successfully running tsql code from C# but when I try to run the sp_attach_db stored procedure it fails. The same code works fine when run in SQL Server 2005 Management Studio...
I tried this:
CN = new SqlConnection(LoginSQLClient.Connection);
//Open connection and execute insert query.
SqlTransaction transaction = CN.BeginTransaction();
//Set insert query
string qry = "exec sp_attach_db 'MyDataBase','C:\\Data\\ MyDataBase.mdf','C:\\Data\\ MyDataBase _log.ldf' ";
//Initialize SqlCommand object for insert.
SqlCommand SqlCom = new SqlCommand(qry, CN);
SqlCom.Transaction = transaction;
I get mostly Synatx errors but this synatax works in Management Studio - Can anyone see why this is not working??