简体   繁体   English

尝试从C#代码运行脚本SQL时System.Data.SqlClient.SqlException

[英]System.Data.SqlClient.SqlException when try to run script SQL from C# code

I've installed SQL Server 2012 Express. 我已经安装了SQL Server 2012 Express。 I'm doing some test with this and Server 2008 Express. 我正在用这个和Server 2008 Express进行一些测试。

With 2008, all is ok. 2008年,一切都还可以。 But with the 2012, I get some troubles. 但随着2012年,我遇到了一些麻烦。

I'm using it from my c# app, with code like this: 我在我的c#app中使用它,代码如下:

t = server.ConnectionContext.ExecuteNonQuery("SELECT * FROM sys.server_principals");

The query in the row above is only a test I've done, after the script I need get error. 在我需要获取错误的脚本之后,上面一行中的查询只是我已经完成的测试。

But, also this get the same error: MODIFY FILE failed. 但是,这也得到了同样的错误: MODIFY FILE失败了。 Specified size is less than or equal to current size . 指定的大小小于或等于当前大小 But why? 但为什么? I saw around that this error comes when something is done about the log... or not? 我在周围看到这个错误来自于对日志做了什么......或者没有?

Why I get this error? 为什么我会收到此错误? The login data are correctly. 登录数据是正确的。 This a new installation, so I am logged in as sa (the script will then create a new user). 这是一个新安装,所以我以sa身份登录(然后脚本将创建一个新用户)。

The same script works perfectly with SQL Server 2008 Express. 相同的脚本与SQL Server 2008 Express完美配合。 I don't get why with 2012 is in this way.. what am I missing? 我不明白为什么2012年就是这样..我错过了什么? Further, I install both 2008 and 2012 from command line with the same parameter: 此外,我使用相同的参数从命令行安装2008和2012:

/q /hideconsole /action=Install /features=SQL /instancename=SQLEXPRESS 
/securitymode=SQL /sapwd=xxx /enableranu=1 /sqlsvcaccount="NT Authority\Network Service" 
/AddCurrentUserAsSqlAdmin /IAcceptSqlServerLicenseTerms  
/skiprules=RebootRequiredCheck

Anyway, the script I want to run is (but, as I said, also the simply SQL above causes the error): 无论如何,我想运行的脚本是(但是,正如我所说,上面的简单SQL也会导致错误):

IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = ****')
    CREATE LOGIN [icaddb] 
       WITH PASSWORD = '****', DEFAULT_DATABASE = [master],   
       DEFAULT_LANGUAGE = [us_english], CHECK_EXPIRATION = OFF, CHECK_POLICY = ON
GO

EXEC sys.sp_addsrvrolemember @loginame = ****', @rolename = N'sysadmin'
GO

EDIT: 编辑:

在此输入图像描述

The problem was this: 问题是这样的:

CREATE DATABASE [IN4MATICSystemSCRIPT_TEST2] 
GO
ALTER DATABASE IN4MATICSystemSCRIPT_TEST2 MODIFY FILE 
( NAME = N'IN4MATICSystemSCRIPT_TEST2' , SIZE = 8384KB , MAXSIZE =     UNLIMITED, FILEGROWTH = 1024KB )
GO
ALTER DATABASE IN4MATICSystemSCRIPT_TEST2 MODIFY FILE 
( NAME = N'IN4MATICSystemSCRIPT_TEST2_log' , SIZE = 24384KB , MAXSIZE =     2048GB , FILEGROWTH = 10%)
GO

Solved removing these rows. 解决了删除这些行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Data.SqlClient.SqlException C# - System.Data.SqlClient.SqlException C# 尝试从 C# 插入 SQL 行,抛出异常:'System.Data.SqlClient.SqlException' - Trying to insert SQL row from C#, throws exception: 'System.Data.SqlClient.SqlException' Linq Windows窗体C#System.Data.SqlClient.SqlException - Linq Windows Form C# System.Data.SqlClient.SqlException C#MySQL错误System.Data.SqlClient.SqlException: - C# MySQL error System.Data.SqlClient.SqlException: c#System.Data.SqlClient.SqlException(0x80131904) - c# System.Data.SqlClient.SqlException (0x80131904) System.Data.SqlClient.SqlException:','附近的语法不正确。 C# - System.Data.SqlClient.SqlException: 'Incorrect syntax near ','.' c# System.Data.SqlClient.SqlException - System.Data.SqlClient.SqlException 'System.Data.SqlClient.SqlException' - 'System.Data.SqlClient.SqlException' 当我尝试使用Windows Universal PlatformApp连接到SQL Server 2008R2时出现System.Data.SqlClient.SqlException - System.Data.SqlClient.SqlException when I try to connect to SQL Server 2008R2 with a Windows Universal PlatformApp System.Data.SqlClient.SqlException:'尝试在数据库中插入数据时无效的对象名称(C#,Visual Studio) - System.Data.SqlClient.SqlException: 'Invalid object name when trying to insert data in database (C#, Visual Studio)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM