Link to home
Start Free TrialLog in
Avatar of nickward26
nickward26Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Keep getting a Database Error in my WCF MVC Website.

Hello,

I have a WCF and Mvc project, the project has been split up into different sections;

DataAccess project - this is essentially a class library which has all the database functionality in (i.e. Connection strings, Database file)

Wcf middleware - this is the WCF service project.

Website

The project is essentially a Mvc Form with some textboxes and a submit button.

The problem i have is everytime I debug the project, i keep getting this error;

Cannot open database "ViewModelsContext" requested by the login. The login failed.
Login failed for user 'NicksPC\Nick.Ward'.


this is my connection string;

<add name="ViewModelsContext" connectionString="Server=.\SQLEXPRESS;AttachDBFilename=C:\Development\DevProjects\Uploader\Main\Source\FrontEnd\Web\Uploader.DataAdapter\App_Data\UploaderDB.mdf;Database=UploaderDB;Trusted_Connection=Yes" providerName="System.Data.SqlClient"/>

    public class ViewModelsContext : DbContext
    {
        public ViewModelsContext()
            : base("ViewModelsContext")
        {
            Database.SetInitializer<ViewModelsContext>(null);
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
           modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
           base.OnModelCreating(modelBuilder);
        }
       
        public DbSet<Uploader.Customer> Customers { get; set; }
    }
}

The connection string is stored in the App.Config file which is in the DataAccess Project

The Middleware project calls the DataAccess layer, shown;

        public Customer SaveCustomerDetails(RetailUploader.Customer customerDetails)
        {
            CustomerData cust = new CustomerData();
            //cust.SaveCustomers(customerDetails);
            return cust.SaveCustomers(customerDetails);
        }

In the website project, it calls the WCF service, shown;

        [HttpPost]
        public ActionResult Upload(Customer cust)
        {
            if (ModelState.IsValid)
            {
                CustomerDataUpload test = new CustomerDataUpload();

                test.SaveCustomerDetails(cust);
            }
            return View();
        }

I have also mapped the model in the textbox controls, sample shown;

<%= Html.TextBoxFor(model => model.Title, new { id = "first_name", @class = "uploader_form_input required minlength alpha" })%>

I am just abit baffled as to why it keeps complaining about the Database Connection.

Thanks,
Nick Ward
ASKER CERTIFIED SOLUTION
Avatar of Matt Bowler
Matt Bowler
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nickward26

ASKER

The advise i was recieved was excellent and helped to solve my problem,