gpt4 book ai didi

c# - MySQL:服务器不存在或连接被拒绝

转载 作者:行者123 更新时间:2023-11-29 10:49:35 25 4
gpt4 key购买 nike

我有一个在 localhost:3306 下运行的 MySQL 数据库。使用像sequel pro这样的程序,我可以毫无问题地连接到数据库。

如果我尝试使用连接字符串在 asp .net core 和 Dapper 中连接这些数据库:

<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient"
connectionString="Server=127.0.0.1;Database=test;User ID=admin;Password=secret;" />
</connectionStrings>

我收到以下错误消息:

System.Data.SqlClient.SqlException (0x80131904): Server does not exist or connection refused.

我不知道为什么。有人可以帮我吗?

最佳答案

我认为您的连接字符串是 underspecified因为它缺少端口号。 3306是specific to MySQL ,因此必须明确声明如下:

connectionString="Server=tcp:.,3306;Database=test..."

关于c# - MySQL:服务器不存在或连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43978531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com