无法使用C#AWS Lambda函数连接到SQL Server Express

时间:2017-01-12 12:55:03

标签: aws-lambda amazon-rds sqlclient

尝试使用System.Data.SqlClient通过AWS Lambda连接到我的SQL Server Express RDS实例时出现以下错误:

  

“errorType”:“PlatformNotSupportedException”,
  “errorMessage”:“此平台不支持操作。”,
  “stackTrace”:[
  “在System.Runtime.InteropServices.OSPlatform.get_Windows()”,
  “at System.Data.SqlClient.SNI.SNITCPHandle.d__22.MoveNext()”
  ]

我使用Amazon.Lambda.Tools构建部署包。运行该函数并从本地连接到数据库工作正常,但在尝试在AWS Lambda上运行时失败。

这是我的project.json

{
"version": "1.0.0-*",
"description": "AWS lambda Console Application",
"authors": [ "" ],
"packOptions": {
    "tags": [],
    "projectUrl": "",
    "licenseUrl": ""
},
"buildOptions": {
    "emitEntryPoint": true
},
"dependencies": {
    "Microsoft.NETCore.App": {
    "type": "platform",
    "version": "1.0.0"
    },
    "Newtonsoft.Json": "9.0.1",
    "Amazon.Lambda.Core": "1.0.0*",
    "Amazon.Lambda.Serialization.Json": "1.0.1",
    "Amazon.Lambda.Tools": {
    "type": "build",
    "version": "1.0.0-preview1"
    },
    "Dapper": "1.50.2",
    "System.Data.SqlClient": "4.3.0"
},
"tools": {
    "Amazon.Lambda.Tools": "1.0.0-preview1"
}, 
"commands": {
    "AwsLambda": "run"
},
"frameworks": {
    "netcoreapp1.0": {
        "imports": "dnxcore50"
    }
}
}

3 个答案:

答案 0 :(得分:5)

有同样的问题而且对我来说只是改变

    from jnius import autoclass, cast


    PythonService = autoclass("org.renpy.android.PythonService")
    activity = cast("android.app.Service", PythonService.mService)
    manager = activity.getPackageManager()
    Intent = autoclass("android.content.Intent")
    intent = manager.getLaunchIntentForPackage("com.MyTest.AndroidTest")
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    activity.startActivity(intent) ### Exception in this line

"System.Data.SqlClient": "4.3.0"

为我工作。我没有必要更改NetCore.App依赖项。

答案 1 :(得分:2)

明确添加对

的引用
"System.Data.SqlClient": "4.1.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0"

解决了这个问题。

答案 2 :(得分:1)

您可以尝试更改

"System.Data.SqlClient": "4.3.0"

"System.Data.SqlClient": "4.1.0"

并更改

"dependencies": {
    "Microsoft.NETCore.App": {
    "type": "platform",
    "version": "1.0.0"
    },

"dependencies": {
    "Microsoft.NETCore.App": {
    "type": "platform",
    "version": "1.0.1"
    },