用C#连接外部SQL数据库
发布时间:2020-12-15 08:14:45 所属栏目:百科 来源:网络整理
导读:我在外部服务器上有一个SQL服务器和数据库设置(为了这个目的,让我们调用域名“hello.com”),我想通过C#程序连接到这个服务器.到目前为止,我有这个(所有服务器/数据库的详细信息与真实的不同): private static void SetupSQL(){ string connectionString = "
我在外部服务器上有一个SQL服务器和数据库设置(为了这个目的,让我们调用域名“hello.com”),我想通过C#程序连接到这个服务器.到目前为止,我有这个(所有服务器/数据库的详细信息与真实的不同):
private static void SetupSQL() { string connectionString = "server=hello.com; database=db1; uid=user1; pwd=xxxxx;"; connection = new SqlConnection(); connection.ConnectionString = connectionString; try { connection.Open(); Console.WriteLine("Connected"); } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } } 这给了我一条错误信息: 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) 我检查了所有连接字符串,并且允许远程访问,因为我已经在同一台计算机上打开查询数据库的SQLWorkbench. 有任何想法吗? 解决方法
你需要MySQL驱动程序:
http://dev.mysql.com/downloads/connector/net/ 然后,您可以使用MySqlConnection连接类进行连接. MySqlConnection connection = new MySqlConnection(connectionString); http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |