What is Partition resolver in ASP.NET? - asp.net

i am new to terms used for server farms setup. There is an attribute called partitionResolverType.
Can someone please explain in easy words what is this partition resolver in the SQL server out-of-proc session state setup?
Thanks!

You specify what kind of session state you want to use, as described here.
If you are using either OutOfProcSessionStateStore (another machine) or SqlSessionStateStore, you may want to change the target machine or Sql server connection at runtime. For example, you may have three machines or Sql servers that you use as backing stores in order to reduce the load on session management.
You can write your own class (custom PartitionResolverType) that ASP will call at runtime to ask for either an IP address or Sql connection string. Your class implements the ResolvePartition(object key) method and returns a string, which is the IP address or Sql connection string of your session store.
You can find a good example here.

Related

ASP.Net MVC database first, database connections

I need help!
We have winforms app with existing large db (SQL), and I have started the project that aims to reproduce some of the logic on the web. For this purpose I decided to use Asp.Net MVC database first approach.
But! There are a lot of Views, Procedures and Functions in our db that based on connected user host_name()+host_id() (for example, filtering views by permissions or filling the temp tables for current user (connection)), but Web connection (with IIS) provides the same host_id() and host_name() for all it's connections, so I try to find approach that will allow me to recognize the connection (one user can have few connections) in SQL with the minimum db object changes.
Have any idea?
You can supply the value for HOST_NAME() from the client by including the WSID=newName in the connection string.
So in your application code, you'll have to obtain the connecting machine's hostname, then generate a connection string on the fly containing the WSID parameter, and pass that connection string to Entity Framework.

project of file storage system in asp.net how to implement correctly?

on upload.aspx page i have
conn1.ConnectionString = "Data Source=.\ip-of-remote-database-server;AttachDbFilename=signup.mdf;Integrated Security=True;User Instance=True";
and all the queries are also on same page ,only database on another machine..
so is this the correct way of implementing ?? or i have to create all queries on another machine and call them by application??
Any given query query might originate from the client code (such as ASP.NET), or it might be stored a-priori in the DBMS itself as a VIEW or a stored procedure (or even a trigger).
But no matter where it originated from, the query is always executed by the DBMS server. This way, the DBMS can guarantee the integrity of data and "defend" itself from the bugs in the client code.
The logical separation of client and server is why this model is called client/server, but that doesn't mean they must be separate physical machines - you'll decide that based on expected workload1 and usage patterns2.
1 Distributing the processing to multiple machines might increase performance.
2 E.g. you might need several "fat" clients around the LAN (communicating with the same database server) to reach all your users. This is less relevant for Web where there are additional layers of indirection between users and the database.
It depends on your infrastructure. If you have got Sql Server locally you can use it. I assume that it is a school project so it does not matter. In real life it usually a good idea to separate web server and database server

Session storage on a separate server

I use 3 server through "Amazon balancer". On each server installed 2 (asp.net) web application (website, mobile site). "Balancer-Amazan"- so constituted that every 3 hours produces load transfer between servers, all session will be crash and creating a new (the users logs off)
Advise the possible solutions to the problem.
Thanks in advance.
If you have SQL Server available you can store your session state in that:
HOW TO: Configure SQL Server to Store ASP.NET Session State
You could even implement your own if SQL Server is not available:
http://msdn.microsoft.com/en-us/library/ms178588.aspx
How to: Sample Session-State Store Provider
The only caveats are that you can only store serialisable objects in the store, i.e. you wouldn't, for example, be able to store a System.Xml.XmlDocument object without turning it's representation into something than can be serialised, i.e. a string representing the XML.
I wrote up another answer that may be useful/provide further reading:
ASP.NET Session size limitation

hosting the database on a remote server while developing

I was wondering if it's possible to host my database on a remote server and still run the application on my local machine while I'm developing it.
I'm using asp.net.
Thanks.
Yes, rather than using . or the name of your machine as the server, just put in the IP address.
So if you're just using a connection string
Data Source=yourRemoteServer;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Too bad the post with the reference to "SO is not your personal research assistant is gone" lol. It is pretty involved! You are first going to have to decide where to host the database, then register a new account with them, create the database, setup your schema or manage to use their janky import functionality, gather the connection string from their service, go to your web.config file and update your connection string to reflect their connection string, and vuala.

Can you query different databases on the same server using 1 NHibernate Session?

Does a new SessionFactory and Session object have to be created for each database? I have a data store for my application data, and a separate data store for my employee security, which is used to validate users. Do I have to create a new SessionFactory ans Session object for calls to the 2 different databases?
ok so this doesn't answer your question directly but it might offer an insight as to why you should create multiple session objects for each datastore.
This article explains how you can implement a thread safe lazy singleton for each type of Session you need so that you only have one session per datastore but it's shared across the entire application. So at most you're only ever going to have 2 session objects.
To directly answer your question however, you will need 1 session object per database.
General case
The general case answer is no, you need at least different sessions for the general case.
You may use a single session factory by using the OpenSession overload taking an opened connection as argument, allowing you to switch database for the session requiring it.
This has some drawbacks, like lack of connection auto-releasing after transactions, disabling of second level cache, ... Better have two session factories in my opinion, rather than supplying your own connection on session opening.
Database specific cases
Depending on the database server you use, you may be able to use a single connection string for accessing both with NHibernate. If you can use a single connection string, then you can use a single session factory and use the same session for accessing your entities split between two databases.
Simplest case
Using SQL Server, you may have your two databases on the same SQL Server. In such case, you can use a single connection string and adjust the catalog attribute on your <class> mappings for telling in which database the table is to be found. (schema can be used too, by appending a dot. It is available in NHibernate since longer, so with an old version you may only have schema.)
Of course, the connection credentials must be valid for accessing both databases.
Other cases
Still using SQL Server, if the second database is on another server, you may use a linked server. You would adjust again the catalog attribute on classes requiring it for specifying the appropriate linkedServerName.DbName.
Maybe other databases could have similar solutions.

Resources