Store ABP Autid Log in separate database - abp

In ABP 4, is it possible to store the Audit Log in a separate database, to save the core database becoming bloated?
For my client Audit Log is nice to have, but not business critical. As such they don't want it backed up with the main database data. Is is possible to configure Audit Logging with a different connection string so that the Audit Log tables can live in a separate database?

yes it is possible.
In ABP Framework, every module has their own DbContext and different connection name for them.
See: https://docs.abp.io/en/abp/latest/Connection-Strings
In your appsettings.json, you can set different ConnectionStrings for any DbContext.
For audit logging, your settings should be as below for appsettings.json.
Here the documentation: https://docs.abp.io/en/abp/latest/Modules/Audit-Logging#connection-string
"ConnectionStrings": {
"Default": "Server=localhost;Database=MyMainDb;Trusted_Connection=True;",
"AbpAuditLogging": "Server=localhost;Database=MyAuditLoggingDb;Trusted_Connection=True;"
}
It's so easy to do with ABP :)

Related

Recreate database when running ASP.NET Core Web API on another server

I have a project that is an ASP.NET Core Web API using Entity Framework Core.
A few time ago I created the database using code-first approach with the necessary migrations.
Now I want run the project in other machine and I get the error when I try for example an post to one endpoint:
Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "MyDatabase" requested by the login. The login failed.
However I think the problem (and I checked with ssms) is that the database doesn't exist.
My connection string, in DbContext is:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(#"Server=(localdb)\mssqllocaldb;Database=MyDatabase;Trusted_Connection=True;");
}
What is the best way to recreate the database on this machine?
Thanks
Remove
;Database=MyDatabase
From the connection string.
Then you can create the dtaabase
CREATE DaTABASE MyDatabase
After the command has run
USE MyDatabase
so that you can create tables and run sql commands on it.
This will wrk on any database.
You should check prior to the creation if the database exists, bu that is highly depending on the rdms that you are using

Should we delete physical database for the deleted clients in SAAS application

I am working on a project which is in .net core and hosted on azure and being used as SAAS application by different clients all over the world having separate databases.
Now I got a requirement which says we should delete the databases of those clients which are no longer in master db and deleted by admin.
I am in doubt that should we really delete the database for the clients which would be getting deleted?
Also if yes is it feasible to delete the database through application or we should use some utility to do that?
Also I am afraid if server will allow application to delete the database?
Can any one please suggest me on this?
Following tech stack i am using:
.net core (backend) with EF core
MSSQL (database)
Theres a few different ways.. Essentially it works the same as any other database, so you can execute T-SQL to do it.. or use the Azure SDK.. Here is some examples of different approaches: https://learn.microsoft.com/en-us/sql/t-sql/statements/drop-database-transact-sql?view=sql-server-2017
You can execute raw SQL statements in EF like so:
using(var context = new SampleContext())
{
var commandText = "INSERT Categories (CategoryName) VALUES (#CategoryName)";
var name = new SqlParameter("#CategoryName", "Test");
context.Database.ExecuteSqlCommand(commandText, name);
}
So, using that format, you could add your DROP Database command in? Taken from: https://www.learnentityframeworkcore.com/raw-sql - under the Database.ExecuteCommand section

Can I use SignalR with SQL Server Backplace on an existing entity code first database?

According to Scaleout with SQL Server you can use SignalR.SqlServer to keep SignalR synced on a load balancing setup. I have an existing MVC 5 website with its own database created using Entity Code First. The article seems to use a dedicated database with service broker enabled and says not to modify the database.
So do I need to have a separate database for this? I know Entity can be picky if the database schema doesn't match and I worry that if I try to use the SignalR Sql Server package with the existing database that the tables it creates will cause a context changed error.
Also can someone provide me with more information about using the Microsoft.AspNet.SignalR.SqlServer package. The article I linked doesn't give a ton of detail and I don't know if I need to change anything in my hub and groups or if it is all handled automatically.
You should be able to, though you'd likely want to separate your entity framework definitions from signalR. You can either put SignalR in a separate database, or give the two a separate schema.
In terms of configuration, you'll need to make an addition to the Startup class of your web project:
public class Startup
{
public void Configuration(IAppBuilder app)
{
var sqlConnectionString = "connection string here";
GlobalHost.DependencyResolver.UseSqlServer(sqlConnectionString);
this.ConfigureAuth(app);
app.MapSignalR();
}
}

Error accessing stored procedure

We have a .NET3.5 Windows Forms application that calls an ASP.NET SOAP web service on the same server. This web service then saves the data into a SQL Server Express 2005 database, again on the same server.
The application has been deployed internally, as well as to a number of our customers and has worked as expected for over 18 months. However this week, at our main customer's site, the application has started generating an error message on four out of the 10 servers it is deployed on. All of the web service methods use the same connection string, but only one web method is affected.
The connection string has this format:
Data Source=MYSERVER\SQLEXPRESS;Initial Catalog=MyDatabase;
Persist Security Info=True;User ID=MyUser;Password=MyPassword
When the application calls one particular web service method, it is producing an error:
Cannot find the user 'MyDatabase', because it does not exist or you
do not have permission.
There have been no changes to the application to cause this, however the customers' IT people may have made changes to these servers. MyUser has been granted permissions on the stored procedures and is able to connect to all of the other web service interfaces.
The main thing that is confusing me is that the error messages says that the user that does not exist is MyDatabase which is the Initial Catalog name in the connection string.
I have been onsite with the customer and verified that the application is still set up correctly and that all of the other web service interfaces are correctly connecting to the database.
Any suggestions of either possible causes or other things I can check would be gratefully received.
I would strongly advise against removing the dbo. That is the schema name. Simply removing it will imply to the DB to use the default schema, which is probably dbo anyways. So it would accomplish nothing. But by not using the schema name when calling the procedure you can run into naming conflicts. For example, if you have a procedure with the same name in two different schemas in the DB, and you try to call it without a schema name, the DB will not know which one to call, resulting in an exception.

SimpleMembership with SQL Server Express database

I have recently discovered that ASP.NET MVC 4 uses SimpleMembership rather than the traditional ASP.NET Membership provider.
I am looking to use SimpleMembership but I also wish to use an Sql Server express database (I will be using a 'real' Sql Server db later on).
I am used to using aspnet_regsql to setup my sql server databases for application services and therefore inserting the necessary membership tables.
However, this application will not setup a DB to work with SimpleMembership.
Can anyone tell me how to do this?
You will need to comment out the WebSecurity.InitializeDatabaseConnection line of code (otherwise the first time you reach the login form the application will attempt to create the simple membership tables on the defined web.config connection string).
Then you will need to update your account controller code since its was written for simpleMembership use to reflect your chosen membership provider.
Recently I did this by creating an MVC3 project then upgrading it to MVC4 (read the how to upgrade mvc3 to mvc4 section). Not the cleanest but it did prevent me from having to update the account controllers code.
I would recommend to look into InitializeSimpleMembershipAttribute, which is in the folder "Filters"
There is a command to initialize the database. It checks itself, if the tables are already created.
WebSecurity.InitializeDatabaseConnection("connStringName", "UserProfile", "UserId", "UserName", autoCreateTables: true);
The tables are:
UserProfile => in my case, because of the initializer
webpages_OAuthMembership
webpages_Membership
webpages_OAuthToken
webpages_Roles
webpages_UsersInRoles
You can check out the source-code of the aspnetwebstack project

Resources