我尝试连接的数据库位于AWS服务器上,我正在尝试编写一个C#脚本,用于从数据库中提取数据。我能找到的唯一教程是使用localhost。这是我尝试过的一些代码:
static void Main()
{
SqlConnection myConnection = new SqlConnection(
"user id=MyUsername;" +
"password=MyPassword;" +
"server=MyServerName.ctf1qojvktpk.us-west-2.rds.amazonaws.com:3306;" +
"Trusted_Connection=yes;" +
"database=MyDBName; " +
"connection timeout=30");
try
{
myConnection.Open();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
答案 0 :(得分:2)
看起来它是一个mySql数据库。您需要安装MySQL Connector for .NET。
示例connectionstring
<add name="MyConnection" connectionString="server=myamazonserver.eu-central-1.rds.amazonaws.com;user id=rootusername;password=mypassword;database=mydatabasename; Convert Zero DateTime=True; Allow User Variables=True" providerName="MySql.Data.MySqlClient" />
或以普通代码
static void Main()
{
SqlConnection myConnection =
new SqlConnection(
"server=myamazonserver.eu-central-1.rds.amazonaws.com;user id=rootusername;password=mypassword;database=mydatabasename; Convert Zero DateTime=True; Allow User Variables=True" providerName="MySql.Data.MySqlClient"
);
try
{
myConnection.Open();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}