简体   繁体   中英

Connecting ASP.NET MVC with Database, error: 26 - Error Locating Server/Instance Specified

I'm trying to create a record in my database with Stripe server response values, ie, I'll be getting a response in javascript and I've to update my model. For this, I'm creating a model variable in database :

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

And then I'm trying to update my table using a method I have created in the controller:

This is how I make the call

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

And this is my Create Method in the controller :

[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);
    }
}

After all these when I try to launch the page, I get a huge error message with a heading :

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. I have tried an ajax call and got the same issue

You could set a break point at line

db.CardInfoes.Add(newCard);

And verify the db context is using correct connection string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM