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/
Related
I'm currently using VS2015 and a local instance of MySQL Server (managed through Workbench) to develop a school project.
The project is a Web form app (.NET/C#) which I have never really done before. I have done C# with a MySQL connection in the past but I think it was just a Windows form app, and I had no issues connecting the database to the form.
I'm currently trying to use a GridView element from the toolbox in Visual Studio to connect to my database. When I go in and edit the source settings, I can create a connection and it will see the tables in my database.
I can then click the "Test Connection" button and it will succeed in connecting. However, if I go forward and try to select items to view from the table, and then click "Test Query" I get the following error:
I have Googled the error and tried some of the solutions found on SO like installing the Clear MEF Cache extension, but it didn't solve anything.
Additionally, I've created some functions from scratch to connect and insert data. They also have problems in that trying to insert any more than one value into the table will fail. Like INSERT INTO user_info(user_id, user_name) VALUES ('5', "Bob") will insert the user_id but not the user_name.
Please see here for a tutorial to connect to MySQL and here for filling your DataGridView from MySQL. Make sure you have the correct reference added to your project as well (References > MySQL.Data).
I recently took a .Net project over which exposes DAOs from a Microsoft SQL Database via ServiceStack REST API. The server runs on IIS 7.5
In the AppHost.Configure the complete database schema is created like so...
var dbFactory = new OrmLiteConnectionFactory(DI.DefaultConnectionString, SqlServerOrmLiteDialectProvider.Instance);
using (var db = dbFactory.OpenDbConnection())
{
if (!db.TableExists(db.GetTableName<SomeSpecificDAO>())) //Create table if not exists
{
db.CreateTable<SomeSpecificDAO>();
db.Insert(new SomeSpecificDAO { Data = 0, AnotherData = "", AnSoOne = });
}
/// alot more tables follow....
}
When I now want to extend a DAO (and therefore add a new column to a table for example) I would do this in Visual Studio, test it, and if it works I would remotely add the column via Microsoft SQL Server Management Studio on the live test server since I do not want to loose any data in the database. This is not very fast when having only one column to add, and it can be very cumbersome if there are more tables/columns added or f.e. the datatype of cells is changed.
What is the best practise in updating the database in Visual studio and on the test system? Is it even possible to have a "Code First approach" where I only extend the DAO and then update the databases?
Have a look at this existing thread in the ServiceStack Customer Forums that explains different strategies for handling db schema changes.
I have published a web app, it's running on azure. The web app project I was testing on my computer (localhost) and then on the web app. When I tested to create a new row a data (for example a new person on a PersonTable) It worked on my localhost but when I tested the web app published it throws this error:
Cannot insert the value NULL into column 'ID_ANTEC_PERS', table
'Telejdb.dbo.ANTECEDENTES_PERSONALES'; column does not allow nulls.
INSERT fails. The statement has been terminated.
That column (ID_ANTEC_PERS) is the ID of that table(ANTECEDENTES_PERSONALES), but I set to this column the identity(1,1) property on my sql server DB. When I worked this project in my computer (localhost) I hadn't this problems, I think it is because the project knew the sequence of that auto increment property. But now, once the web app is published and running on azure, I wanted to see the code of my project but I realized it was compiled on .dll files So I can't edit the web app project. Any Help? Guide? Suggestions? I will appreciate that.
Thanks in advance
Check the field from your table design then Check the checkbox from your table design then it allows to insert null value in table
id is supposed to be an incrementing value.
You need to set this, or else if you have a non-nullable column, with no default value, if you provide no value it will error.
To set up auto-increment in SQL Server Management Studio:
Open your table in Design
Select your column and go to Column Properties
Under Indentity Specification, set (Is Identity)=Yes and Indentity Increment=1
in local if you are not getting this problem means you have to update the
azure database
Finally I could solve it, the problem was my azure DB tables didn't have identity property (autoincrement) so the table had a PK but it doesn't have their identity property.
What happen?
When I tried to import my local DB (which all its tables have the identity property) to azure DB I didn't by a unknown method (I used the task of SSMS: Task>Export Data...) This could import all the tables, PK Constraints and all the data but it didn't import all the identity properties.
How to fix it?
What I did to solve it was importing my database again but this time in a correct way: importing my local db to azure db by a bacpac file (azure database recognizes this kind of backup file).
Actually, before I used the method to import my DB that I used, I tried importing my db by importing bacpac file but I couldn't because I used SSMS 2014 and researching on another stackoverflow questions I figured out I can't make a bacpac file with SSMS 2014 (I had a problem with clustered Index) but I can do it with SSMS 2016, so I installed it and finally I could create the bacpac file and then I could import it to my azure db, and it had the identity property
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.
I created a windows forms application in C #, and a database MS SQL server 2008 Express, and I use LINQ-to-SQL query to insert and edit data.
The database is housed on a server with Windows Server 2008 R2 (standard edition). Right now I have the application running on five different computers, and users are authenticated through active directory.
One complaint reported to me was that sometimes when different data is entered and submitted, the same data do not appear in the listing that contains the application. I use try catch block to send the errors but errors do not appear in the application; but the data simply disappear.
The id of the table records is an integer auto-increment. As I have to tell them the registration number that was entered I use the following piece of code:
try{
ConectionDataContext db = new ConectionDataContext();
Table_Registers tr = new Table_Registers();
tr.Name=textbox1.text;
tr.sector=textbox2.text;
db.Table_Registers.InsertOnSubmit(tr);
db.SubmitChanges();
int numberRegister=tr.NumberRegister;
MessageBox.Show(tr.ToString());
}
catch{Exception e}
I wonder if I'm doing something wrong or if you know of any article on the web that speaks how to insert data from different clients in MSSQL Server databases, please let me know.
Thanks.
That's what a database server DOES: "insert data simultaneously from different clients".
One thing you can do is to consider "transactions":
http://www.sqlteam.com/article/introduction-to-transactions
Another thing you can (and should!) do is to insure as much work as possible is done on the server, by using "stored procedures":
http://www.sql-server-performance.com/2003/stored-procedures-basics/
You should also check the SQL Server error logs, especially for potential deadlocks. You can see these in your SSMS GUI, or in the "logs" directory under your SQL Server installation.
But the FIRST thing you need to do is to determine exactly what's going on. Since you've only got MSSQL Express (which is not a good choice for production use!), perhaps the easiest approach is to create a "log" table: insert an entry in your "log" every time you insert a row in the real table, and see if stuff is "missing" (i.e. you have more entires in the log table than the data table).