适用于SQL Server Linux的AWS Codebuild连接字符串

时间:2019-05-20 20:40:05

标签: docker asp.net-core aws-codebuild sql-server-linux

我正在尝试使用AWS Codebuild构建ASP.NET Core 2.2应用程序

为此,我使用Dockerfile运行以下命令:

  • dotnet恢复
  • 构建
  • 单元测试(xUnit)
  • 与SQL Server的集成测试(xUnit)

为了满足集成测试的SQL Server依赖性,我得到了AWS Codebuild来启动运行SQL Server Linux的Docker容器(您可以在pre_build的{​​{1}}阶段中看到它)下面的文件

我遇到的问题是CodeBuild表示在集成测试期间ASP.NET Core App无法连接到SQL Server Linux容器。

我尝试了许多不同的连接字符串组合,但所有组合都不起作用:

buildspec.yml

我已经让Codebuild运行"Server=127.0.0.1,1433;Database=My.Database;User Id=sa;Password=SecurePassword!" "Server=localhost,1433;Database=My.Database;User Id=sa;Password=SecurePassword!" "Server=host.docker.internal,1433;Database=My.Database;User Id=sa;Password=SecurePassword!" 命令,因此我可以验证SQL Server Linux容器是否确实在构建主机上运行。

请让我知道更多信息是否有帮助。

Codebuild返回的错误是:

docker ps -a

我的Codebuild配置如下:

Starting test execution, please wait... 
Master ConnectionString => Data Source=mssql,1433;Initial Catalog=master;User ID=sa;Password=*************** 
·[91m[xUnit.net 00:00:16.82]     MyApp.IntegrationTests.JobScenarios.Get_JobAsync_HappyPath_ReturnsOKStatusCode [FAIL] 
·[0mFailed   MyApp.IntegrationTests.JobScenarios.Get_JobAsync_HappyPath_ReturnsOKStatusCode 
Error Message: 
 System.Data.SqlClient.SqlException : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught) 
---- System.Net.Internals.SocketExceptionFactory+ExtendedSocketException : No such device or address 
Stack Trace: 
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken) 
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) 
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) 
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) 
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) 
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) 
   at System.Data.SqlClient.SqlConnection.Open() 
   at SqlServerExtensions.SqlDatabase(SupportedDatabasesForEnsureDatabase supported, String connectionString, IUpgradeLog logger, Int32 timeout, AzureDatabaseEdition azureDatabaseEdition, String collation) 
   at MyApp.DBDeploy.DbUpDeploy.DeployDatabase(String connectionString) in /src/src/MyApp/DBDeploy/DbUpDeploy.cs:line 11 
   at MyApp.IntegrationTests.ScenariosBase`1.CreateTestServer() in /src/tests/MyApp.IntegrationTests/ScenariosBase.cs:line 56 
   at MyApp.IntegrationTests.Scenarios.Get_MyMethodAsync_HappyPath_ReturnsOKStatusCode() in /src/tests/MyApp.IntegrationTests/Scenarios.cs:line 98 
--- End of stack trace from previous location where exception was thrown --- 
----- Inner Stack Trace ----- 
   at System.Net.Dns.InternalGetHostByName(String hostName) 
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress) 
   at System.Data.SqlClient.SNI.SNITCPHandle.Connect(String serverName, Int32 port, TimeSpan timeout) 
   at System.Data.SqlClient.SNI.SNITCPHandle..ctor(String serverName, Int32 port, Int64 timerExpire, Object callbackObject, Boolean parallel) 

我的"projects": [ { "logsConfig": { "s3Logs": { "status": "DISABLED" }, "cloudWatchLogs": { "status": "ENABLED", "groupName": "/codebuild/test/" } }, "timeoutInMinutes": 60, "name": "TestCodeBuildProject", "serviceRole": "arn:aws:iam::<account_id>:role/service-role/codebuild-TestCodeBuildProject-service-role", "tags": [], "artifacts": { "type": "NO_ARTIFACTS" }, "lastModified": 1558382502.768, "cache": { "type": "NO_CACHE" }, "created": 1558295505.314, "environment": { "computeType": "BUILD_GENERAL1_MEDIUM", "privilegedMode": true, "image": "aws/codebuild/standard:2.0", "type": "LINUX_CONTAINER", "environmentVariables": [] }, "source": { "buildspec": <buildspec.yml>, "insecureSsl": false, "location": "https://github.com/MyGitRepo.git", "gitCloneDepth": 1, "type": "GITHUB", "reportBuildStatus": false }, "badge": { "badgeEnabled": false }, "queuedTimeoutInMinutes": 480, "secondaryArtifacts": [], "secondarySources": [], "encryptionKey": "arn:aws:kms:<aws_region>:<account_id>:alias/aws/s3", "arn": "arn:aws:codebuild:<aws_region>:<account_id>:project/TestCodeBuildProject" } ] 文件如下:

buildspec.yml

0 个答案:

没有答案