-4

Context

I am using Visual Studio 2013, and I have created an ADO.Net Entity Data Model which connect to my SQL Server 2014 database.

I can retrieve my data and display it using RESTful services.

Problem

But I can't insert a data into any table (delete and edit too).

Is my connection set to read-only mode? I looked to the properties of my DB but nothing points to that option.

Any help?!

Edited:

Here is my code of WCF Service. Below is Create() body:

using (OnlinestoreEntities ose = new OnlinestoreEntities())
{
    try
    {
        UserEntity user = new UserEntity();
        user.Id = _user.Id;
        user.Name = _user.Name;
        user.Password = _user.Password;
        user.Email = _user.Email;

        ose.UserEntities.Add(user);
        ose.SaveChanges();

        return true;
    }
    catch
    {
        return false;
    }
};

The following code is Create() on the client side (using MVS model), this function is called from the controller when clicks in the Add User link:

public bool Create(User user)
{
    try
    {
        var webClient = new WebClient();
        DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User));

        MemoryStream mem = new MemoryStream();
        ser.WriteObject(mem, user);

        string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);

        webClient.Headers["Content-type"] = "application/json";
        webClient.Encoding = Encoding.UTF8;

        String str = webClient.UploadString(BASE_URL + "create", "POST", data);
        return true;
    }
    catch
    {
        return false;
    }
}

Do you still need any details, I thought the problem was about DB settings?!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
BDeveloper
  • 1,175
  • 6
  • 24
  • 44
  • 1
    We **cannot possibly** answer your question, if you're **NOT SHOWING** us anything! Show us your connection string, show us the code you're using to try and insert or delete data. After all - we cannot see your screen, nor read your mind ! – marc_s Dec 12 '15 at 14:43
  • Done!! is that better – BDeveloper Dec 12 '15 at 15:05
  • Well, for one - I'd try to actually **capture** what happens in your exceptions - don't just "silently" return false. If something goes wrong - the **exception** (and possible `.InnerException`) will tell what's wrong - you need to know that info! – marc_s Dec 12 '15 at 15:14

1 Answers1

1

Look like the username you are using to connect the SQL database have read only access. You should use some other username which have permission to do DML operation.

In case you not have another username then you have to contact the DBA for your SQL server

EDIT

When installing SQL server you will get option to configure, how your authenticate SQL Server (i.e. Windows Authentication mode or Mixed Mode). I'll prefer mixed mode.

Then after selecting mixed mode you have to configur your 'SA' password.

To me its look like you are using windows authentication, and only you have admin access and Everyone else configure as readonly.

When you deploy ASP.Net application in IIS. By default It take the AppPoolIdentity to open SQL connection, which not have any permission to do DML operation

Avinash Jain
  • 7,200
  • 2
  • 26
  • 40
  • that's what am talking about, actually i am the DBA where this is a local project, is there any option while installing the SQL Server that put me in the Read only mode. or while connecting. i'm using the windows authentication, does that matter? – BDeveloper Dec 12 '15 at 15:04
  • in the DB Properties, under the Permission Tap: there is Users or Roles. i have added guests and public users and gave them the all rights to delete/insert/edit. but nothing changed? – BDeveloper Dec 12 '15 at 15:09
  • ok i will re-install the SQL Server, thnx for helping, appreciated! – BDeveloper Dec 12 '15 at 15:11
  • thnx for your answers, it was a problem of Permission. When i run the visual studio as administrator it worked fine. at least i knew that the problem wasn't in my code. – BDeveloper Dec 13 '15 at 00:48