2014-09-05 77 views
0

HI我正在嘗試將數據插入Azure上託管的數據庫。我得到一個豁免錯誤。我在本地數據庫上測試了下面的代碼,它工作正常。 Azure需要一些額外的代碼嗎?未將數據插入Azure SQL數據庫

 protected void Submit_Click(object sender, System.EventArgs e) 
    { 
     SqlConnection conn; 
     SqlCommand comm; 
     string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; 
     conn = new SqlConnection(connectionString); 
     comm = new SqlCommand("INSERT INTO Site (SiteName, SiteEmail) VALUES (@SiteName, @SiteEmail)", conn); 
     comm.Parameters.Add("@SiteName", System.Data.SqlDbType.Text); 
     comm.Parameters["@SiteName"].Value = "Whatever Time, Place"; 
     comm.Parameters.Add("@SiteEmail", System.Data.SqlDbType.Text); 
     comm.Parameters["@SiteEmail"].Value = "[email protected]"; 
     try 
     { 
      conn.Open(); 
      comm.ExecuteNonQuery(); 
      label1.Text = "It worked"; 
     } 
     catch 
     { 
      label1.Text = "Error submitting the form!"; 

     } 
     finally 
     { 
      conn.Close(); 
     } 
    } 
+0

你有什麼異常? – Teppic 2014-09-06 01:49:25

回答

1

如果您還沒有這樣做,您需要配置您的Azure SQL Server以允許來自客戶端的連接。

這可以從在Azure門戶中通過導航到SQL服務器配置選項卡,將您的客戶端的IP地址允許的IP地址列表來完成:

enter image description here

0

感謝您的答覆。我重寫了我的看法,以提供更多的細節。這是一個聚集索引錯誤。

此版本的SQL Server不支持沒有聚集索引的表。請創建聚集索引並重試。

由於某些原因,除了一個以外,所有表都有一個聚集索引。