无法连接使用MonoTouch的为sql Azure数据库 [英] can't connect to sql azure database using monotouch

查看:152
本文介绍了无法连接使用MonoTouch的为sql Azure数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#和MonoTouch的一个iPhone项目。
我需要使用SQL Azure数据库。
我的问题是,我似乎无法使用MonoTouch的获得连接。
我可以做下面的工作罚款code内置使用的Visual Studio 2012在Windows 8机器上的本地控制台应用程序。
但是,当我尝试将它移植到一台iMac和使用的MonoDevelop / MonoTouch的我的iPhone应用程序崩溃。
我得到的错误是:

System.NotImplementedException:客户端和服务器之间发送的数据SSL加密不落实

我周围的谷歌了一下,发现这似乎来形容我的确切问题的此处。我注意到它的快两岁了,所以我不知道这仍然是未实现的。

所以,我试图改变StringBuilder.Encrypt =真正的价值;为false。
但是,它仍然崩溃,我得到的错误:

Mono.Data.Tds.Protocol.TdsInternalException:服务器关闭了连接。 ---> System.IO.IOException:连接丢失

在这两种情况下应用程序崩溃时conn.Open();被调用。

我是pretty卡住了,我没有选择,只能使用SQL Azure上。
所以,如果任何人都可以提出一个解决方案或解决了我的问题,我会AP preciate大大。
在此先感谢!

 字符串username =<用户名> @< myservername>中;
        字符串密码=<密码和GT;
        字符串数据源=< myservername> .database.windows.net
        字符串的databaseName =<&DBNAME GT;        SqlConnectionStringBuilder connStringBuilder;
        connStringBuilder =新SqlConnectionStringBuilder();
        connStringBuilder.DataSource =数据源;
        connStringBuilder.InitialCatalog =的databaseName;
        connStringBuilder.Encrypt =真;
        connStringBuilder.TrustServerCertificate = FALSE;
        connStringBuilder.UserID =用户名;
        connStringBuilder.Password =密码;
        使用(SqlConnection的康恩=新的SqlConnection(connStringBuilder.ToString())){            conn.Open();            使用(IDbCommand的dbcmd = conn.CreateCommand()){
                字符串SQL =从dbo.client选择client_username;;
                dbcmd.CommandText = SQL;
                使用(IDataReader的读卡器= dbcmd.ExecuteReader()){
                    而(reader.Read()){
                        字符串的用户名=(字符串)读卡器[client_username];
                    }
                }
            }
        }


解决方案

SSL进行SqlConnection类未实现。见<一href=\"https://github.com/mono/mono/blob/master/mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs#L819-L823\"相对=nofollow> SqlConnection.cs

和作为Azure的要求加密连接你就必须做一些变通。例如,你可以创建一个Web角色和揭露其执行代表你的SQL Web服务。

I'm working on a iphone project using c# and monotouch. I need to use an SQL Azure database. My problem is that I cant seem to get connected using monotouch. I can make the code below work fine in a native console application built on a windows 8 machine using visual studio 2012. But, when I try to port it over to an imac and use monodevelop/monotouch my iphone app crashes. The error I get is:

System.NotImplementedException: SSL encryption for data sent between client and server is not implemented.

I google around a bit and found a bug report that seems to describe my exact issue here. I noticed its almost two years old so i'm not sure if this would still be unimplemented.

So, I tried changing the value of StringBuilder.Encrypt = true; to false. But, it still crashes and I get the error:

Mono.Data.Tds.Protocol.TdsInternalException: Server closed the connection. ---> System.IO.IOException: Connection lost

in either case the app crashes when conn.Open(); is called.

I'm pretty stuck, and I don't have a choice but to use SQL Azure. So, if anyone could suggest a solution or work around for my issue, I'd appreciate it greatly. thanks in advance!

        string userName = "<username>@<myservername>";
        string password = "<password>";
        string dataSource = "<myservername>.database.windows.net";
        string databaseName = "<dbname>";

        SqlConnectionStringBuilder connStringBuilder;
        connStringBuilder = new SqlConnectionStringBuilder();
        connStringBuilder.DataSource = dataSource;
        connStringBuilder.InitialCatalog = databaseName;
        connStringBuilder.Encrypt = true;
        connStringBuilder.TrustServerCertificate = false;
        connStringBuilder.UserID = userName;
        connStringBuilder.Password = password;


        using (SqlConnection conn = new SqlConnection (connStringBuilder.ToString())) {

            conn.Open();

            using (IDbCommand dbcmd = conn.CreateCommand()){
                string sql = "Select client_username from dbo.client;";
                dbcmd.CommandText = sql;
                using (IDataReader reader = dbcmd.ExecuteReader()){
                    while( reader.Read() ){
                        string username = (string) reader["client_username"];
                    }
                }
            }
        }

解决方案

SSL for SqlConnection class is not implemented. See SqlConnection.cs

And as Azure requires an encrypted connection you'll have to do some workaround. For example you could create a web role and expose a web service which executes the SQL on your behalf.

这篇关于无法连接使用MonoTouch的为sql Azure数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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