Adding and reading from from azure mobile service - c#

I created a mobile service app using azure connected it to SQL DB that has this table
now trying to insert and retrieve data in my Windows Universal App gives me this error:
I tried many things one of them was this code:
HighScore item = new HighScore
{
SCORE = "100",
playerName = "Mark"
};
await App.MobileService.GetTable<HighScore>().InsertAsync(item);
tried also to get the table bu name but no luck, now what is weird for me is that this same code works perfectly on the TodoItem Table but not on other tables.
Thanks in advance

The MobileServiceInvalidOperationException is a wrapper exception. The actual exception is in an InnerException inside that object. Based on the error message, your insert is not working.
You have provided no information on how you constructed the backend. Don't forget that you need to create the table in the SQL database and you need to create an appropriate controller for exposing the database table to your mobile client.
You have not provided any information on what the entity on your mobile client looks like. It needs to match the information you want to send to the backend.
Finally, take a look at my book - http://aka.ms/zumobook - Chapter 3 of the book goes into great detail on the data protocol.

Related

Web Service checking that DB is available

I need to create an ASP.NET web service that simply returns an information telling if a database is available or down when it's consumed.
So I would like to know if I can set a task that is executed inside the web service method on a regular basis to check the connection to the database and return the result via a URL.
No you cannot. Well, you could, but you really should not. A webservice is on demand. If it's called, it does work. If it's not called, it's not running.
You may have been thinking of a windows service. That is something that is always running and can do stuff in the background.
(A windows service may have an additional web frontend to see it's data. Or any other way to visualize it's data points, for example another database.)
As you tagged c# and asp so you are using Sql server database,
this query gives you databases that exists on your sql server instance:
select * from master.dbo.sysdatabases
result contains name and some extra information, name gives you database names, mode column have a int value indicates that database is in creating mode or created mode, status column that contains a int value(power of 2)
If you would like to see if database is offline or not, you can see status value if it is 512 your database is offline, for 1024 it is in read only mode
for your service you can use web api, web method or wcf, it is depend on you
If you use hangfire, quartz or any other scheduler you can set a background job on your server to check your database status
"return the result via a URL" I can not understand this, but if you want to notify users about database you can use push notification on your background job

Add column to Azure SQL Database and display using Azure Mobile Services

I'm a newbie to dealing with Azure SQL Databases and Mobile Services. Does anyone know if it is possible to add a column to Azure SQL Database without having to go through the publish process in Visual Studio? When I download the mobile services project from Azure, I can publish the service and it will run with a new ToDoItems table. So I open up a SQL query in Visual Studio and add a column and add some random data to the new column 'Individual':
ALTER TABLE Numboo.TodoItems
ADD Individual nvarchar(max)
INSERT INTO Numboo.TodoItems (Text,Complete,Deleted,Individual)
VALUES ('90987834',1,0,'test data xxxxx')
But when I request the data from the table using mobile services, the data in the new column is null when I query the table
private MobileServiceCollection<TodoItem, TodoItem> demo;
private IMobileServiceTable<TodoItem> demoTable = App.MobileService.GetTable<TodoItem>();
demo = await demoTable.ToCollectionAsync();
//Individual is null
instead of "test data xxxxx" which I inserted via a sql query. Does anyone know if this is even possible to do it this way (add a column via script and access it using mobile services)? Or point me in the right direction or to an answer on SO if there is one? I'm not sure what I would be searching for. Thanks.
NB: I have updated the model/entity to reflect the new column in the database but that didn't make any difference:
You do need to deploy your service with an updated model that matches the table schema/the model you want your API to expose. It's not enough to just change the client model.
Now, your question is specifically about publishing from VS, and although a deployment is required, you have other deployment options, including continuous deployment, which you can learn more about here:
https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-store-code-source-control/

Using WCF Data Services to copy one database table to another

I am little stuck in using LINQ to insert one database table to another database table located on another server as a WCF Data Service.
Suppose I have an Item class on the local database and the same Item class on the the remote server, and I want to copy all the records across.
Is there a possibility to do this from: -
private Uri svcUri = new Uri("someurl/WcfDataService.svc");
Entities = new Entities(svcUri);
.....
I know that LINQ to SQL is mostly a 1-1 mapping between classes and the database, but I heard it is possible.
You just need to construct a connectionstring pointing at the right database. That database has to have the tables the EF expects to have though. (The code would look like yours, but I've never used a Uri for a connection string.)
However, it would be more efficient to do via a stored procedure on your source database, via a Linked Database to y=the Target. This because if you do it via WCF the data has to travel twice: SourceDB -> WCF service -> TargetDB, whereas with a SP it only has one hop: SourceDB -> TargetDB. Also in the SP it will operate pretty much as a set operation whereas the WCF service will have to process one row at a time.
EDIT - Apologies: I didn't notibe the MySQL tag. I don't know whether MySQL supports Linked Databases, so feel free to ignore this if it doesn't.

Watch a sql table continuously for a particular value

i was trying to connect a local machine with my web application.i need to get some data from local machine and insert it into my online table.User clicks a button and a new column is added to a online table named request which has status "new" in the beginning.i went for sql dependency which i installed as a windows service in local machine and it check the request table for any new insert.the service fetches some data from the local machine and posts it to the online database and change the status field in request table to "updated".
Now my problem is how can i notify my website that required data has been inserted in the table?? i need to watch the request table continuously until the value in the status column changes to updated.can i go for thread or timer ??
You can write an INSERT trigger in the live database which your website is using.
Use another Table RequestUpdates and write an INSERT trigger that adds a value to the table RequestUpdates in the live database.
Design your website to load the RequestUpdates table.
And when the user loggs in and Requests have been viewed, change the status in the live table to viewed.
In this way new requests will be shown that are not viewed the next time.

Limiting records synchronized to mobile device

Similar questions have been asked before but after a day of going through the answers I'm still very confused.
I'm using Microsoft's Sync Framework with SQL2008 on the server and SQL CE on Windows Mobile devices. I would have thought this was a VERY common requirement. I don't want to replicate large tables onto the mobile device. I only want the records that are needed. For example, each user will need their "jobs" out of the jobs table. They don't need any other user's jobs. So I need something like "where jobId = 3" for one device and "where jobId=4" for another etc.
This looked promising: http://jtabadero.spaces.live.com/blog/cns!BF49A449953D0591!1203.entry
but unfortunately it doesn't work with my code. This code from the sample seems to be trying to get the code that contains the SQL:
var remoteProvider = (LocalDataCache1ServerSyncProvider)syncAgent.RemoteProvider;
var selectIncrementalInsertsCommand = remoteProvider.SalesLT_CustomerSyncAdapter.SelectIncrementalInsertsCommand;
BUT the code containing the SQL (generated by VS) is on the server-side and only a proxy is available in the client-side code. This is how the proxy is added:
// The WCF Service
var webSvcProxy = new MicronetCacheSyncService();
// The Remote Server Provider Proxy
var serverProvider = new ServerSyncProviderProxy(webSvcProxy);
// The Sync Agent
var syncAgent = new MicronetCacheSyncAgent();
syncAgent.RemoteProvider = serverProvider;
So how can I get to the server-side code that contains the sql from the client-side? Sorry I'm not explaining this very well but I guess it's unlikely anyone will have an answer. The short version is does anyone know a SIMPLE way to limit the records that are synced to a mobile device is this type of app? I think the example was meant for desktop apps.
It looks to me like this sync framework is another one of Microsoft's half-baked releases that is really just a beta. It's starting to remind me of some previous horrible experiences with Entity Framework 1.0 :(
The tutorial at http://msdn.microsoft.com/en-us/library/dd918848%28SQL.105%29.aspx contains everything you need to provision filtering for a scope.
FYI, that tutorial is for Sync Framework 2.0, whereas from your code above it appears you're using Sync Framework 1.0 -- a legacy product.

Categories

Resources