locked
{Message: "An error has occurred.", ExceptionMessage: "Invalid object name 'dbo.users_tbl'.",…} RRS feed

  • Question

  • User991566988 posted

    Hi All

    I've implemented the application at this link: http://www.webcodeexpert.com/2013/11/aspnet-mvc-application-to.html

    but with Web API and connection by MySQL by this Connection String:

    <connectionStrings>
      <add name="test" connectionString="server=127.0.0.1;User Id=root;password=SomePassword;database=sham"
    providerName="MySql.Data.MySqlClient" />
      </connectionStrings>

    I'm trying to call "Postusers_tbl" by this view:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Create</title>
    
        <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
        <style>
            form {
                border: 3px solid #f1f1f1;
            }
    
            input[type=text], input[type=password] {
                width: 100%;
                padding: 12px 20px;
                margin: 8px 0;
                display: inline-block;
                border: 1px solid #ccc;
                box-sizing: border-box;
            }
    
            button {
                background-color: #4CAF50;
                color: white;
                padding: 14px 20px;
                margin: 8px 0;
                border: none;
                cursor: pointer;
            }
    
                button:hover {
                    opacity: 0.8;
                }
    
            .cancelbtn {
                width: auto;
                padding: 10px 18px;
                background-color: #f44336;
            }
    
            .imgcontainer {
                text-align: center;
                margin: 24px 0 12px 0;
            }
    
            img.avatar {
                width: 40%;
                border-radius: 50%;
            }
    
            .container {
                padding: 16px;
            }
    
            span.psw {
                float: right;
                padding-top: 16px;
            }
        </style>
    
    </head>
    <body>
    
        <h2>Create Form</h2>
    
        <form>
    
            <div class="container">
                <label><b>fname</b></label>
                <input type="text" placeholder="Enter First Name" id="fname" name="fname" required>
                <label><b>lname</b></label>
                <input type="text" placeholder="Enter Last Name" id="lname" name="lname" required>
                <label><b>dob</b></label>
                <input type="text" placeholder="Enter Date of Birth" id="dob" name="dob" required>
                <label><b>gender</b></label>
                <input type="text" placeholder="Enter Gender" id="gender" name="gender" required>
                <label><b>phone number</b></label>
                <input type="text" placeholder="Enter Phone Number" id="phone_number" name="phone_number" required>
                <label><b>Email</b></label>
                <input type="text" placeholder="Enter Email" id="email" name="Email" required>
            </div>
    
    
            <div class="container">
                <input type="submit" class="btn btn-success" value="Create" />
                <input type="button" class="btn btn-primary" onclick="location.href='index.html';" value="Login" />
    
            </div>
    
    
        </form>
    
    </body>
    </html>
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
    
        $("form").submit(function (event) {
    
            event.preventDefault();
    
            var fnamev = $("#fname").val();
            var lnamev = $("#lname").val();
            var dobv = $("#dob").val();
            var genderv = $("#gender").val();
            var phone_numberv = $("#phone_number").val();
            var emi = $("#email").val();
    
            if ($.trim(fnamev).length > 0 & $.trim(lnamev).length > 0) {
                $.ajax({
                    type: "post",
                    dataType: 'json',
                    url: 'http://localhost:4096/api/Users/Create',
                    data: { fname: fnamev, lname: lnamev, dob: dobv, gender: genderv, phone_number: phone_numberv, email: emi },
                    crossDomain: true,
                    cache: false,
                    success: function (data) {
                        alert('success');
    
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        // If error happened
                    }
                });
            } else {
                alert('Please fill the required fields!');
            }
        });
    </script>
    
    

    when pressing the button it gives me this error:

    {Message: "An error has occurred.", ExceptionMessage: "Invalid object name 'dbo.users_tbl'.",…}

    I think because model thinks it trying to connect to table users_tbl on SQL Server not MySQL!!

    Why? and How to solve Plz?

    Note: I'm trying to create the model via ADO.NET Entity Data Model but is doesn't create the users_tbl class it self and also its context one!

    Wednesday, July 12, 2017 9:55 AM

All replies

  • User1168443798 posted

    Hi musbah,

    >> I'm trying to create the model via ADO.NET Entity Data Model but is doesn't create the users_tbl class it self and also its context one!

    It seems you want DataBase first and you did not create the model correctly.

    I would suggest you follow below link step by step.

    # Using MySQL with Entity Framework

    https://www.codeproject.com/Tips/426790/Using-MySQL-with-Entity-Framework

    Best Regards,

    Edward

    Thursday, July 13, 2017 5:11 AM