Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to run Sql Scripts using MigrationBuilder up

$
0
0

I m trying to run sql scripts using 

public partial class RunMySqlScripts : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {

            //var sqlFilesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring‌​(0, AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), "SqlScriptsUp");
            var sqlFile = Path.Combine(AppContext.BaseDirectory, "SqlScriptsUp"); migrationBuilder.Sql(File.ReadAllText(sqlFile));
        }

I keep getting this error when i run 

Update-Database
Access to the path 'D:\ARTSQLCORE\ARTSQLCORE\ARTNetCore\bin\Debug\netcoreapp2.0\SqlScriptsUp' is denied.

I m using ASP.NET Core 2

Detailed Run (PMC),

PM> update-database
Applying migration '20170808095807_RunMySqlScripts'.
System.UnauthorizedAccessException: Access to the path 'D:\ARTSQLCORE\ARTSQLCORE\ARTNetCore\bin\Debug\netcoreapp2.0\SqlScriptsUp' is denied.
   at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks)
   at System.IO.File.InternalReadAllText(String path, Encoding encoding)
   at System.IO.File.ReadAllText(String path)
   at ARTNetCore.Data.Migrations.RunMySqlScripts.Up(MigrationBuilder migrationBuilder) in D:\ARTSQLCORE\ARTSQLCORE\ARTNetCore\Data\Migrations\20170808095807_RunMySqlScripts.cs:line 14
   at Microsoft.EntityFrameworkCore.Migrations.Migration.BuildOperations(Action`1 buildAction)
   at Microsoft.EntityFrameworkCore.Migrations.Migration.<.ctor>b__4_1()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
   at Microsoft.EntityFrameworkCore.Migrations.Migration.get_UpOperations()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c__DisplayClass13_2.<GetMigrationCommandLists>b__2()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Access to the path 'D:\ARTSQLCORE\ARTSQLCORE\ARTNetCore\bin\Debug\netcoreapp2.0\SqlScriptsUp' is denied.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>