0

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'.

J. Steen
  • 15,470
  • 15
  • 56
  • 63
Yasin Caner
  • 131
  • 1
  • 5
  • 16
  • 7
    Please refrain from using bastardised English. "u" and "4" are not words. – J. Steen Dec 07 '12 at 13:38
  • 1
    The problem is with the format of your connection string. I don't have the correct syntax to hand, but this might be useful: http://connectionstrings.com/ – Jude Fisher Dec 07 '12 at 13:40
  • @JcFx well, i read so many things and all of them have done like this. but really i cant find a really good aritcle. i created this script with VS2012 , is that a problem? it look like empt when compared with that http://stackoverflow.com/questions/2250297/how-to-run-a-sql-script-using-c-sharp – Yasin Caner Dec 07 '12 at 14:02

1 Answers1

3

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

"Data Source=(local);Initial Catalog=DatabaseName;Integrated Security=True;";
Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50
  • ahh yeah thx when i fix it i got another error :( ; FileLoadException ; Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without addinitonal configuration information is there aFramework error? – Yasin Caner Dec 07 '12 at 14:03
  • See here for an answer to the mixed mode assembly problem: http://stackoverflow.com/questions/2455654/what-additional-configuration-is-necessary-to-reference-a-net-2-0-mixed-mode – Eric Dahlvang Dec 07 '12 at 14:12
  • one more question , sorry for that but it gives Failed to connection , do i have to install SqlServer or we can fix just Visual Studio? or do i have to open a port? – Yasin Caner Dec 07 '12 at 14:33
  • You cannot connect to Sql Server if the service is not installed and running on the machine. Your connection string has "(local)" as the Data Source. This means that you are trying to connect to the Sql Server instance on the local machine. So yes, you need to install it. – Eric Dahlvang Dec 07 '12 at 14:50
  • sorry for all problems but it is hard to find a article mean full article so it is hard to understand what is going on , thanks again – Yasin Caner Dec 07 '12 at 14:55
  • Okey it is working ; but i need to ask u, when i run script with this connectionstring "Data Source=(local);Initial Catalog=master;Integrated Security=True;"; it created but i cant find in Sql Management studio? Why and when i use it on gridview how can i find connection path? it is a big question for me – Yasin Caner Dec 07 '12 at 19:40