2016-11-01 48 views
0

我想創建一個記錄在我的數據庫與條紋服務器響應值,即,我會得到一個響應JavaScript和我必須更新我的模型。對於這一點,我在數據庫中創建一個模型變量:連接ASP.NET MVC與數據庫,錯誤:26 - 錯誤定位服務器/實例指定

var values = { 
    "CardType": response.card.brand, 
    "Name": response.card.name, 
    "LastFour": response.card.last4, 
    "Email" : @Membership.GetUser().Email, 
    "Token": response.id 
} 

然後我嘗試使用我已經在控制器中創建的方法來更新我的表:

我這是怎麼做通話

$.post("@Url.Action("Create")",values,function(data) 
{ 
    alert("I have reached here"); 
}); 

這是我在控制器中創建方法:

[HttpPost] 
public ActionResult Create(CardInfo newCard) 
{ 
    ViewBag.StripeKey = ConfigurationManager.AppSettings["StripePublishableKey"]; 
    if (ModelState.IsValid) 
    { 
     db.CardInfoes.Add(newCard); 
     db.SaveChanges(); 

     return RedirectToAction("About"); 
    } 
    else 
    { 
     return View(newCard); 
    } 
} 

畢竟這些,當我嘗試啓動頁面,我得到一個巨大的錯誤消息標題:

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

PS。我曾嘗試Ajax調用並得到了相同的問題

+0

**我的意思是說:我使用JavaScript中的模型屬性創建變量** –

+0

什麼是連接字符串?你確定可以從你的Web服務器訪問SQL,並且你可以使用Sql管理工作室連接到它?有時你需要啓用遠程連接,如果SQL在另一臺服務器上 –

回答

-1

您可以設置在線路

db.CardInfoes.Add(newCard); 

一個破發點,並驗證該數據庫上下文中使用正確的連接字符串。

+0

當我嘗試在我的網頁中啓動創建視圖時出現此錯誤 –

+0

這應該是一個評論而不是答案 –

相關問題