Friday, February 24, 2012

C# code to attach database to sql express

i need this help , i am trying but its not getting attached

in command lprompt its working good but comming to c# code its not working

first i am copying database and log file to data folder then i used this code

string AttachCommand = @."CREATE DATABASE myrokero ON ( FILENAME = N '"+sqlPath+"myrokero.mdf' ),( FILENAME = N'"+sqlPath+"myrokero.ldf' ) FOR ATTACH ";

processStart = new ProcessStartInfo("sqlcmd.exe ", " -E -q " + AttachCommand.ToString());

processStart.UseShellExecute = false;

processStart.RedirectStandardOutput = true;

processStart.RedirectStandardError = true;

processStart.CreateNoWindow = true;

process = Process.Start(processStart);

process.WaitForExit();

Didi you debug your command to execute to see if the executed SQL is the same as your sql executed in QA with the right syntax ? DId you then try to attach the database with the debbuged code to see if that works ? If so and it worked, there could be probably a security issue within the Process you are starting, try to start that with SQL Authentication. Or try to impersonate the process with the current credentials of the current Windows identity.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment