Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用connectionString连接到MySQL服务器_C#_Mysql_.net_Mysql Workbench - Fatal编程技术网

C# 无法使用connectionString连接到MySQL服务器

C# 无法使用connectionString连接到MySQL服务器,c#,mysql,.net,mysql-workbench,C#,Mysql,.net,Mysql Workbench,我可能错过了一些愚蠢的事情…但我整天都在想办法,所以我放弃了。 有人能发现错误吗 App.config <connectionStrings> <add name="linkednDb" connectionString="Server=.;Database=linkedin.usernames;Uid=root;Pwd=1234;" providerName="System.Data.SqlClient"/> 忘记添加错误 System.Data.SqlClie

我可能错过了一些愚蠢的事情…但我整天都在想办法,所以我放弃了。 有人能发现错误吗

App.config

  <connectionStrings>
<add name="linkednDb" connectionString="Server=.;Database=linkedin.usernames;Uid=root;Pwd=1234;" providerName="System.Data.SqlClient"/>

忘记添加错误

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'

在配置中的connectionString值中,我认为应该是“Database=linkedin”,而不是“Database=linkedin.usernames”。数据库值不需要表名

System.Data.SqlClient
是Sql Server的ADO.Net提供程序,它是一个与MySql完全不同的数据库平台

您需要一个MySql提供程序。此提供程序不包含在.Net开箱即用中,但您可以在Visual Studio中安装和引用


在这里,SQL代码中的字符串替换是不正常的。SQL查询中的字符串替换非常容易受到SQL注入问题的影响。这是应用程序最终被黑客攻击的主要方式之一。也可以减少恶意问题的发生;它不接受l33t黑客的攻击,因为这会导致问题。老Joe的普通用户可以通过输入真实数据来破坏应用程序。您需要学习如何使用参数化查询。

错误消息是什么您是否收到错误消息、意外结果或其他信息?你用的是整洁的吗?因为这是个坏主意
对于Dapper,这仍然是我们不愿意添加的内容-不值得进行安全权衡:)
而不是参数化查询您正在执行一个动态生成的字符串,该字符串可能很容易无效。例如,如果用户名是
O'Reilly
?您将得到
插入用户名(UserName)值('O'Reilly')
和一个无效的查询错误
System.Data.SqlClient
是SQL Server客户端。您无法使用它连接到MySQL@fubo是的,问题被标记为
mysql
,而代码使用了一个mysql连接字符串。好的,第一个问题已经解决,现在要更改语句,谢谢!
 public static class Helper
{
    public static string Connection(string name)
    {
     return ConfigurationManager.ConnectionStrings[name].ConnectionString;  
    }
}
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'