簡體   English   中英

聯盟扇出查詢

[英]Federation Fan Out Query

我是SQL Azure中的新手。 現在,我面臨一個大問題,這是因為SQL Azure聯合身份驗證。 在我的項目之一中,我想使用聯合身份驗證。 為此,我想從所有聯合會中讀取數據。 如何檢查服務器中的聯盟總數並從聯盟讀取數據? 還有如何將數據插入聯合身份驗證? 目前我正在使用:

string strSQL = @"SELECT f.name, fmc.federation_id, fmc.member_id, fmc.range_low, fmc.range_high " +
                                                            "FROM sys.federations f " +
                                                            "JOIN sys.federation_member_distributions fmc " +
                                                            "ON f.federation_id=fmc.federation_id " +
                                                            "ORDER BY fmc.federation_id, fmc.range_low, fmc.range_high";
        string strTableName = "federation_member_distributions";

        try
        {
            using (SqlConnection connection = new SqlConnection(csb.ToString()))
            {
                connection.Open();
                sbResults.AppendFormat("-- Open {0}\r\n\r\n", csb.ToString());

                data = new DataSet();
                data.Locale = System.Globalization.CultureInfo.InvariantCulture;

                using (SqlCommand command = connection.CreateCommand())
                {
                    // Connect to federation root or federation member
                    command.CommandText = "USE FEDERATION ROOT WITH RESET";
                    command.ExecuteNonQuery();
                    sbResults.AppendFormat("{0}\r\nGO\r\n", command.CommandText);
                }

                //Retrieve federation root metadata, and populate the data to the DataGridView control
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(strSQL, connection);
                sqlDataAdapter.Fill(data, strTableName);
                sbResults.AppendFormat("{0}\r\nGO\r\n", strSQL);
            }

        }
        catch (Exception ex)
        {

        }

但這不起作用

對於上述問題,您確實需要查看這些文章,這些文章討論如何使用SQL Azure Federation:

SQL Azure中聯盟的扇出查詢簡介(第1部分):多個聯盟成員上的可擴展查詢,MapReduce樣式!

在上方,您可以找到Fanout示例工具 ,該工具的代碼向您展示了如何從聯盟中獲取數據。

該示例的第二部分“ 在SQL Azure中進行聯合查詢的扇出查詢(第2部分):具有TOP,ORDER BY,DISTINCT和其他強大聚合的可伸縮扇出查詢,MapReduce樣式! ”展示了如何運行扇出帶有特定示例的查詢。

嘗試上述示例,讓我們知道您是否遇到任何問題。

我與SQL Azure團隊的Cihan Biyikoglu進行了討論,他的建議如下:

這個想法是,您不必使用聯合身份驗證來緩存數據所在的“地圖”,因此您不必這樣做。

這是偽應用程序代碼和執行扇出的實際示例; 您也可以在此用戶界面中嘗試代碼。

http://federationsutility-seasia.cloudapp.net/About.aspx

Start at the 
@i=MIN_VALUE (of the data_type or federation key like customerID=-1)
While (@i not null)
{
 Try
 {
    -- switch to the next member
    USE FEDERATION fedname(id=@i)...

    -- Run your transaction here for this member 
    SELECT * FROM table join other_table … WHERE fedkeycolumn >= @i group by … order by …

    -- grab the next value
    SELECT @i=range_high FROM sys.federation_member_distributions 
 }
 Catch ()
 {
           If retry_count < total_retries
                          Exit the loop
 }
}

如果您仍然想找出成員,則可以始終在包含聯合身份驗證的數據庫中運行查詢;

Select * from sys.federation_member_distributions fmd join sys.federations f on fmd.federation_id=f.federation_id 

這種方法的問題是,如果您在讀取信息的時間和完成處理查詢的時間之間存在時間間隔,則可能會錯過讀取數據的時間。

沒有緩存“地圖”的上述方法不容易出現該問題。 它將捕獲所有成員,而不管任何重新分區操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM