从AWS CodeDeploy运行sqlpackage.exe会引发异常

时间:2017-01-01 22:21:45

标签: amazon-web-services sql-server-data-tools aws-code-deploy sqlpackage

我正在尝试从AWS CodeDeploy执行的脚本中运行sqlpackage.exe

当以管理员身份登录时,sqlpackage命令从本地CMD提示符运行正常,但在作为CodeDeploy管道的一部分调用时不运行。

发生以下错误:

An unexpected failure occurred: DacInstance with the specified instance_id does not exist..

    Unhandled Exception: System.Data.SqlClient.SqlException: DacInstance with the specified instance_id does not exist.
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

似乎无法与数据库建立连接。

CodeDeploy作为在Local System帐户下运行的Windows服务运行,其中我的命令提示符在Administrator帐户下运行。这是唯一的区别,所以我认为这必须是权限问题。

看来dacpac需要由具有sysadmin权限的用户安装。我尝试(作为测试)将SQL Server用户NT AUTHORITY\SYSTEM设置为DBCreator

然后部署失败并出现以下错误。

The database settings cannot be modified. You must be a SysAdmin to apply these settings.
The database settings cannot be modified. You must be a SysAdmin to apply these settings.
An error occurred while the batch was being executed.
Updating database (Failed)

我不确定如何继续。我猜这个NT AUTHORITY\SYSTEM SysAdmin是个坏主意!

1 个答案:

答案 0 :(得分:0)

CodeDeploy Host Agent Service作为LocalSystem用户运行,该用户应具有NT AUTHORITY \ SYSTEM和BUILTIN \ Administrators权限。 这就是CodeDeploy代理执行脚本的方式:

  Governorates_names = Arrays.asList("Ad Dakhiliyah"
                ,"Ad Dhahirah"
                ,"Al Batinah North"
                ,"Al Batinah South"
                ,"Al Buraimi"
                ,"Al Wusta"
                ,"Ash Sharqiyah North"
                ,"Ash Sharqiyah South"
                ,"Dhofar"
                ,"Muscat"
                ,"Musandam");
        if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Ad Dakhiliyah"))
            state_names = Arrays.asList("Nizwa","Samail","Bahla","Al Hamra","Manah","Izki","Adam"  );

        else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Ad Dhahirah"))
            state_names = Arrays.asList("Ibri","Yanqul","Dhank");

        else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Al Batinah North")){
            state_names = Arrays.asList("Sohar","Shinas","Liwa","Saham","Al Khaburah","Suwayq");

        }else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Al Batinah South")){
            state_names = Arrays.asList("Nakhal","Wadi Al Maawil","Al Musanaah","Barka","Rustaq");

        }else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Al Buraimi")){
            state_names = Arrays.asList("Al Buraimi","Mahdah","Al Sinas");

        }else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Al Wusta")){
            state_names = Arrays.asList("Haima","Duqm","Mahout","Al Jazur");

        }else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Ash Sharqiyah North")){
            state_names = Arrays.asList("Ibra","Al-Mudhaibi","Bidiyah","Wadi Bani Khaled","Dema Wa Thaieen","Al Qabil");

        }else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Ash Sharqiyah South")){
            state_names = Arrays.asList("Masirah","Sur","Jalan Bani Bu Hassan","Jalan Bani Bu Ali","Al Kamil Wal Wafi");

        }else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Dhofar")){
            state_names = Arrays.asList("Salalah","Taqah","Mirbat","Thumrait","Sadah","Rakhyut","Dhalkut","Muqshin","Shalim and the Hallaniyat Islands","Al-Mazyona");

        }else if(String.valueOf(Governorates_nameedt.getText().toString()).equals("Dhofar")){
            state_names = Arrays.asList("Muttrah","Bawshar","Seeb","Al Amarat","Qurayyat");

        }else if( String.valueOf(Governorates_nameedt.getText().toString()).equals("Musandam")){
            state_names = Arrays.asList("Khasab","Bukha","Daba Al Bayah","Madha");


        }

        final ArrayAdapter<String> Governorates_name_Opt = new ArrayAdapter<>(personal_info.this, android.R.layout.simple_spinner_dropdown_item, Governorates_names);
        final List<String> finalOpt1 = Governorates_names;
        Governorates_nameedt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertDialog.Builder(personal_info.this)
                        .setTitle("Select ")
                        .setAdapter(Governorates_name_Opt, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Governorates_nameedt.setText(finalOpt1.get(which).toString());
                                dialog.dismiss();
                            }
                        }).create().show();
            }
        });
        final ArrayAdapter<String> state_name_Opt = new ArrayAdapter<>(personal_info.this, android.R.layout.simple_spinner_dropdown_item, state_names);
        final List<String> finalOpt2 = state_names;
        state_nameedt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AlertDialog.Builder(personal_info.this)
                        .setTitle("Select ")
                        .setAdapter(state_name_Opt, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                state_nameedt.setText(finalOpt2.get(which).toString());
                                dialog.dismiss();
                            }
                        }).create().show();
            }
        });

如果您将可执行文件放在部署程序包中的文件夹中,则可以尝试将该可执行文件与appspec.yml文件一起放在根目录中。 话虽如此,我们看来这个问题与早期版本的主机代理有关,应该使用2017年3月发布的最新版本来解决。