C#.net mysql连接问题 [英] C#.net mysql connection problem

查看:78
本文介绍了C#.net mysql连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C#.net连接远程MySQL数据库,但没有连接。始终显示消息

'无法连接到任何指定的MySQL主机。'。

如何修复它。





我的尝试:



 string ConnString =SERVER = nepalidiary.com; Port = 3306; DATABASE = bsslearn_db; UID =''; PWD ='abc';; 
string SQL =select * from tbl_StudentProfile;

MySqlConnection cnn = new MySqlConnection();
cnn.ConnectionString = ConnString;
MySqlCommand cmd = cnn.CreateCommand();

cnn.Open();

cmd.ExecuteNonQuery();

解决方案

猜测 - 无法访问您的数据库全部它可能是 - 你的UID错了,和/或你的密码。



网络连接的数据库有一个空白的用户,或者这样的琐碎是不寻常的密码 - 网络允许任何人进入,所以他们应该比这复杂得多。



首先检查你的连接字符串与数据库提供者 - 他们将能够准确告诉你要使用什么。



BTW:不要硬编码连接字符串 - 它们确实会改变,所以它们应该存储在实际应用程序之外。

I want to connect Remote MySQL dataase from C#.net but not connecting. always displaying message 

'Unable to connect to any of the specified MySQL hosts.'. 

How to fixed it. 



What I have tried:

string ConnString = "SERVER=nepalidiary.com; Port=3306;DATABASE=bsslearn_db;UID='';PWD='abc';";
            string SQL = "Select * from tbl_StudentProfile";

            MySqlConnection cnn = new MySqlConnection();
            cnn.ConnectionString = ConnString;
            MySqlCommand cmd = cnn.CreateCommand();

            cnn.Open();

            cmd.ExecuteNonQuery();

解决方案

At a guess - and without access to your DB's that's all it can be - you UID is wrong, and / or your password.

It would be unusual for a web connected DB to have a blank user, or such a trivial password - the web allows anyone in, so they should be a lot more complex than that.

Start by checking your connection string with teh DB provider - they will be able to tell you exactly what to use.

BTW: don't hard code connection strings - they do change, so they should be stored outside your actual app.


这篇关于C#.net mysql连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆