Hola amigos en un assemblie que tengo necesito a partir de un parametro que le paso que es el nombre de un fichero que el me compacte ese fichero. pero no me lo hace. me dice que no tiene permisos (en la carpeta) para hacerlo. el fina es que desde mi aplicacion aspx el administrador del sistema puedda hacer un backup de la BD completa sin tener que cargar la interfase de SQL Server. la aplicacion llamara a un procedimiento almacenado:
 

ALTER PROCEDURE [dbo].[salva_database]

@path NVARCHAR(4000),

@database nvarchar(4000)

AS

declare @sql nvarchar(4000)

set @[EMAIL PROTECTED]'.bak'

backup database @database to disk = @sql

execute GZipCompress @sql

y este llamara al assemblie que contiene lo siguiente. el tema es que me da que no hay permisos de lectura escritura para hacer la siguiente operacion de compactar, pero sin embargo si me crea la salva. ¿alguna ayuda?. alguien sabe como hacer salvas de SQL server sin cargar la consola de SQL?. gracias

 

class Compactar

{

public bool GZipCompress(string filename)

{

FileStream infile;

bool bien = false;

try

{

// Open the file as a FileStream object.

infile = new FileStream(filename, FileMode.Open,

FileAccess.Read, FileShare.Read);

byte[] buffer = new byte[infile.Length];

// Read the file to ensure it is readable.

int count = infile.Read(buffer, 0, buffer.Length);

if (count != buffer.Length)

{

infile.Close();

throw new ApplicationException("Unable to read data from file");

return bien =false ;

}

infile.Close();

FileStream ms = new FileStream(filename + ".gz", FileMode.CreateNew);

// Use the newly created memory stream for the compressed data.

GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Compress, true);

compressedzipStream.Write(buffer, 0, buffer.Length);

// Close the stream.

compressedzipStream.Close();

ms.Close();

ms.Dispose();

File.Delete(filename);

return bien = true;

} // end try

catch (InvalidDataException)

{

return bien = false;

}

catch (FileNotFoundException)

{

return bien = false;

}

catch (ArgumentException)

{

return bien = false;

}

catch (PathTooLongException)

{

return bien = false;

}

catch (DirectoryNotFoundException)

{

return bien = false;

}

catch (IOException)

{

return bien = false;

}

catch (UnauthorizedAccessException)

{

return bien = false;

}

catch (IndexOutOfRangeException)

{

return bien = false;

}

}

}

 

Por favor si conoces alguan herramienta para hacer backups en SQL Server sin necesidad de la consola de SQL pues gracias. nos leemos

 

 

Este es el error que me da cuando trata de compactar.

BACKUP DATABASE successfully processed 1851 pages in 3.026 seconds (5.009 MB/sec).

A .NET Framework error occurred during execution of user defined routine or aggregate 'GZipCompress':

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

System.Security.SecurityException:

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)

at System.Security.CodeAccessPermission.Demand()

at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)

at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)

at compactar.compactar.GZipCompress(SqlString filename)

.

Responder a