Can't connect to remote SQL server in C#

好久不见. 提交于 2020-01-03 03:22:13

问题


I created a database on freesqldatabase.com and was in the process of writing a C# script to connect to it and I cannot seem to get it to connect successfully. I think the issue is in the connection string, but I'm not sure what the problem is. I've been trying to get advice from documentation, but I haven't been able to fix it. My connection method is below:

Note: connAddr = sql3.freesqldatabase.com

Note: port = 3306

    public static void Connect(string connAddr, int port)
    {
        CloseConnection();

        Conn = new SqlConnection();

        Conn.ConnectionString =
            "Data Source=" + connAddr + "," + port + ";" +
            "Initial Catalog=sql332572;" +
            "user id=sql332572;" +
            "pwd=xxxxxxxx";
        Conn.Open();
    }

I am getting the below error. Searching Google didn't seem to give me any information on this particular error:

Exception: Unknown packet type 91
Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacketHeader ()
Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacket ()
Mono.Data.Tds.Protocol.TdsComm.GetByte ()

Can you guys see anything wrong with my connection string? Any help is greatly appreciated. Thanks!


回答1:


Try using this format for your connection string:

Server=;Database=;uid=;pwd=;



回答2:


According to http://www.freesqldatabase.com/mssql/

they will launch MS SQL Server connection soon, i.e. they don't provide it now. What are you trying to connect to? If it is MySql than Sqlconnection would not work.



来源:https://stackoverflow.com/questions/22316254/cant-connect-to-remote-sql-server-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!