Frage

I have a little problem about that. When i create a script with VS2012 ,it looks like that (DataBase Name : LSProjeDB and have a table as Musteri) (created like that : 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

but it is looks like wrong!! and i used that c# code :

 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);

and i got :

ArgumentException is unhandled! Keyword not supported: 'datasource'.

War es hilfreich?

Lösung

DataSource <-- you have a space missing between Data and Source

"Data Source=(local);Initial Catalog=DatabaseName;Integrated Security=True;";
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top