Automated process Tabular Model Scripting Language (TMSL) - ssas

I created my tabular model with SSAS and Now I'm looking for a solution to refresh it automatically.
So I have some questions :
could we process our tabular model with a stored procedure T-SQL calling the TMSL script ?
An example will be helpful
Thank's

Yes. This article explains how to setup a SQL Server linked server that connects to SSAS. Once that's done, you can run this:
declare #xmla varchar(max) = '
{
"refresh": {
"type": "full",
"objects": [
{
"database": "YourDatabaseName"
}
]
}
}
';
exec (#xmla) at SSAS;
This approach lets you write some logic to execute different TMSL scripts daily. For example you could refresh only the current year partition.
If you want to execute a static script then a SQL Agent job is another way to go.

Related

Azure Logic Apps 'Execute SQL Query' Connector

I am trying to implement several Azure Logic Apps that query/update an Azure SQL Server Database. The queries return either one value or a table with several rows. I prefer not to create stored procedures, but instead use the 'Execute SQL Query' Connector. My queries are running fine in the Logic Apps, but I have not found a way to extract the output of the queries to use in next steps, or return in an HTTP Response.
Can someone guide me on how this can be done for both single-value and table outputs?
If for some reason you don't want to create a SP, or cannot do it, you can access your custom query results by using this in your JSON:
#body('Name_of_Execute_SQL_Query_step')?['resultsets']['Table1'][0]['NameOfYourColumn']
If you can't find the exact "path" for your data, run and let it fail. Then go check the failing step and there in "Show raw outputs" you will be able to see the results of the Execute SQL Query step. For example:
{
"OutputParameters": {},
"ResultSets": {
"Table1": [
{
"Date": "2018-05-28T00:00:00"
}
]
}
}
To access that date, you'd of course need to use:
#body('Name_of_Execute_SQL_Query_step')?['resultsets']['Table1'][0]['Date']
Stored Procedures are always better for many reasons and the output can be reasonable well inferred by the Connector. That's why Stored Procedure output lights up in the designer.
Execute SQL Actions return 'untyped' content which is why you don't see specific elements in the designer.
To use the Execute SQL output like a Stored Procedure output, you would have to define the JSON Schema yourself, and use the Parse JSON Action to light up the SQL output.

Need to identify C# Method That Is Generating Long Running Query

Is there a way to identify what method in C# code is connecting and executing a query?
My thoughts so far is to generate a unique user for each connection in the application and then examine the SQL Server system tables to view the original_login_user.
I should note that I am using Azure SQL.
The OP is using Entity Framework, and you can log all SQL Queries that EF performs by doing something like
using (var context = new BlogContext())
{
context.Database.Log = Console.Write;
// your code here...
}
See the following for more information: https://msdn.microsoft.com/en-us/library/dn469464(v=vs.113).aspx

Best way to run this query on an SQL Database

I have a website that I host with GoDaddy. At the moment if I want to run an SQL Query on the database I'm using GoDaddy's default phpMyAdmin interface to interact with the database (all done through the browser).
I have a table with 32,000 records. One of the items in the table contains a JSON string that looks something like this:
{
"activity": {
"section1": {
"item1": {
"itemName": {
"name": "myName",
"property1": false,
"property2": false
}
}
},
"section2":{
"item1": false
}
}
}
Overtime I may want to update this JSON string (e.g. if the schema is updated and I want to add a section3 there. If I try to do this now (even if the new string is hardcoded and is the same for each of the 32000 records in the table, the query just times out. I suspect 32000 is too many records for this operation.
I tried running a query through PhpMyAdmin's SQL Query tab - that failed, it got through to about half way and then it timed out.
My question is: what is the best to work with the database? Is there a more efficient way to run queries then through GoDaddy's default phpMyAdmin interface?
I don't know which plan you use at GoDaddy, but you can enable remote access on all paid plans. Then, you can connect to your database using MySQL Workbench tool. I think that's better than PHPMyAdmin.
Another solution is execute the query using PHP (and maybe split up in multiple queries). You can host a PHP script directly on your GoDaddy server.
Anyway, storing JSON files as part of a full-text field is not a good idea. You may read few articles about database normalization. See also this other question.

Generating usable sql from Entity Framework to use for data migrations

I'm having a bit of a mess around at the moment trying to build a console app where I can insert some data into my database and output the sql to a file as an extra. The idea being is that I could use these for data migrations or something similar.
I have several lookup tables that I'd like to pre-populate with data and I think this is nicer than writing out the sql by hand. If someone needs to look up a value it'll be right there in the code.
I'm using EF Tracing and what I've got so far allows me to log the sql entity framework creates by doing the following
I've hooked into their action to get access to the tracing
private void WriteSqlToString(CommandExecutionEventArgs args)
{
sqlTrace.Append(args.ToTraceString());
}
Which gives something like this
insert [dbo].[Members]([EmailAddress], [FirstName], [LastName])
values (#0, #1, #2)
select [Id]
from [dbo].[Members]
where ##ROWCOUNT > 0 and [Id] = scope_identity()
-- #0 (dbtype=String, size=60, direction=Input) = "email#email.com"
-- #1 (dbtype=String, size=-1, direction=Input) = "TestFirstName"
-- #2 (dbtype=String, size=-1, direction=Input) = "TestLastName"
I'll be the first to hold my hand up because I'm not good at writing sql by hand. I've messed about with this a little to try and get it to execute in sqlserver express but keep getting errors because the variables aren't declared.
Do folk think it's worth continuing trying to get this to work or am I missing a better solution here?
Here's some more of the code for reference
public void CreateSqlFile()
{
using (MyContext context = tracingContextFactory.Create(WriteSqlToString))
{
Migrate(context);
context.SaveChanges();
}
StreamWriter file = new StreamWriter(migrationPath);
file.WriteLine(sqlTrace.ToString());
file.Close();
}
The SQL generated from EF is functional, but it is normally overly complex and badly formatted.
Which is fine, for EF, because no-one ever sees the SQL.
However, if you're going to use or try to modify the SQL, I'd go for a different route. If you're trying to do data migrations, for example, I'd look at SQL Server Integration Services (SSIS).
Edit
To generate data to transfer between servers, in SQL Server management studio,
Right click on the database,
Click generate scripts.
Select your table.
On the next screen, choose Advanced Options
In "types of data to script", choose "Data only". (or Schema and Data, as appropriate)
Continue to the end of the wizard
Success.

Is there a way to make EF 5 code first migrations use a sql server database in ASP.NET MVC 4 for everything?

I would like for it to use SQL Server by default for everything when I start a new ASP.NET MVC 4 Web Application project. By default when you run this project it creates a LocalDb instance and creates the following tables in it:
webpages_Membership
webpages_OAuthMembership
webpages_Roles
webpages_UsersInRoles
UserProfile
I have been able to use a code first migration to put the UserProfile table into a SQL server database. However, I have not been able to accomplish this with the other 4 tables.
Obviously my goal is to start with a single SQL Server database and have all of the tables for the application contained within the single database.
Open your InitializeSimpleMembershipAttribute.cs file, this is where the WebSecurity database initialization is. You need to modify it with the correct connectionStringName. Example:
Change
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
to
WebSecurity.InitializeDatabaseConnection("MyRealDBConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
IF you want to copy the structure of the web security tables to use with Code First, there is an article .... which I cannot find at the moment ... give me a few.
Well I could not find it - but honestly - it was a pain. The easiest way, since you have the DB generated already, might be to use an Code First reverse engineer tool like Entity Framework Power Tools. This will do most of the work for you. Then just add the classes to your DbContext, create a migration, and update your real database.
Also - you may need to make more modifications than this - depending on your Context name and such.
If your goal is to only create those tables in your existing db, you should perform 2 steps.
First, change the connection string of db initialization as what #Jack said.
Second, in your DbContext, change the constructor like this:
public class MyDbContext : DbContext
{
publicMytDbContext()
: base("MyRealDBConnection")
{
}
// ...
}