我正在开发一个ASP.NET Core Web API项目。在我的项目中,我使用Hangfire来运行后台任务。因此,我正在配置Hangfire以使用这样的数据库。
public void ConfigureServices(IServiceCollection services)
{
services.AddHangfire(configuration =>
{
configuration.UseSqlServerStorage("Server=(LocalDB)\\MSSQLLocalDB;Integrated Security=true;");
});
//
}
In the above code, I am using Local DB. Now, I am trying to use AWS RDS database since I am deploying my application on the AWS Elastic Beanstalks. I created a function for getting the connection
public static string GetRDSConnectionString()
{
string dbname = "ebdb";
if(string.IsNullOrEmpty(dbname)) return null;
string username = "admin";
string password = "password";
string hostname = "cxcxcxcx.xcxcxcxc.eu-west-2.rds.amazonaws.com:1234";
string port = "1234";
return "Data Source=" + hostname + ";Initial Catalog=" + dbname + ";User ID=" + username + ";Password=" + password + ";";
}
我从AWS官方文档中获得了上述代码。在上面的代码中,我不清楚的是数据库名称,数据库名称总是" ebdb"?我试图找出数据库名称。但不可能。在教程中,它说使用ebdb。所以,我用它。
然后在配置中,我改为此。
configuration.UseSqlServerStorage(AppConfig.GetRDSConnectionString());
当我运行代码时,它给了我这个错误。
Win32Exception: The parameter is incorrect
Unknown location
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: SQL Network Interfaces, error: 25 - Connection string is not valid)
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, object providerInfo, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, bool applyTransientFaultHandling)
Win32Exception: The parameter is incorrect
基本上,我在运行应用程序时无法连接到数据库。但我设置了正确的凭据。我唯一加倍的是数据库名称(ebdb)。我的配置出了什么问题,出了什么问题?我该如何解决?