我对此有一个小问题。当我使用 VS2012 创建脚本时,它看起来像那样(数据库名称:LSProjeDB 并有一个表作为 Musteri)(这样创建:go table > update>genarete script >wow)
GO SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;
SET NUMERIC_ROUNDABORT OFF;
GO
:setvar DatabaseName "C:\USERS\YC\DOCUMENTS\LSPROJEDB.MDF"
:setvar DefaultFilePrefix "C_\USERS\YC\DOCUMENTS\LSPROJEDB.MDF_"
:setvar DefaultDataPath "C:\Users\YC\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0\"
:setvar DefaultLogPath "C:\Users\YC\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0\"
GO
:on error exit
GO
/*
Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
To re-enable the script after enabling SQLCMD mode, execute the following:
SET NOEXEC OFF;
*/
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
BEGIN
PRINT N'SQLCMD mode must be enabled to successfully execute this script.';
SET NOEXEC ON;
END
GO
USE [$(DatabaseName)];
GO
PRINT N'Update complete.'
GO
但它看起来像错了!我使用了那个 c# 代码:
string str = "DataSource=(local);Initial Catalog=DatabaseName ;Integrated Security=True";
FileInfo file = new FileInfo("D:\\SQLQuery2.sql");
string script = file.OpenText().ReadToEnd();
SqlConnection conn = new SqlConnection(str);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
我得到了:
ArgumentException 未处理!不支持关键字:“数据源”。