[英]Programmatically change SQL Server configuration
I want to backup database in SQL Server 2012 using this code: 我想使用以下代码在SQL Server 2012中备份数据库:
BACKUP DATABASE aveed_co
TO DISK = 'C:\bakup.bak'
WITH FORMAT,
MEDIANAME = 'aveed_co',
NAME = 'aveed_co'
After execution this code in SQL Server Management Studio, I get this error: 在SQL Server Management Studio中执行此代码后,出现以下错误:
Msg 233, Level 20, State 0, Line 0
消息233,级别20,状态0,第0行
A transport-level error has occurred when sending the request to the server.将请求发送到服务器时,发生了传输级错误。
(provider: Shared Memory Provider,error: 0
- No process is on the other end of the pipe.)(提供者:Shared Memory Provider,
error: 0
管道的另一端没有进程。)
To solve this problem I must change log on type (in SQL Server configuration) as below: 若要解决此问题,我必须更改登录类型(在SQL Server配置中),如下所示:
In other hand I must change "log on as" from "Built-in account" (1) to "This account" (2). 另一方面,我必须将“登录身份”从“内置帐户”(1)更改为“此帐户”(2)。
When I change "log on as" to "This account" and enter username and password the SQL Server code execute correctly. 当我将“登录身份”更改为“此帐户”并输入用户名和密码时,SQL Server代码将正确执行。
Note that I have permission to write on c: or any driver 请注意,我有权在c:或任何驱动程序上写
Please help me to do this using C# or SQL Server code. 请帮助我使用C#或SQL Server代码执行此操作。
You do not have write permissions on drive C: for your custom user. 您没有自定义用户对驱动器C:的写入权限。 EDIT:
编辑:
var query = @"BACKUP DATABASE [aveed_co]
TO DISK = 'C:\bakup.bak' WITH INIT
,NOUNLOAD
,NAME = N'aveed_co'
,NOSKIP
,STATS = 10
,NOFORMAT
,COMPRESSION";
using (var connection = new SqlConnection(@"Server=myServerAddress;Database=aveed_co;User Id=myUsername;Password=myPassword;"))
{
connection.Open();
using (var command = new SqlCommand(query, connection))
{
command.CommandTimeout = 0;
command.ExecuteNonQuery();
}
}
SQL Server must be able to read and write to the device; SQL Server必须能够读取和写入设备。 the account under which the SQL Server service runs must have write permissions.
运行SQL Server服务的帐户必须具有写权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.