So I set up SQL Server Session State using SQL Server 2008 and the temp database and today I decided to look into the data in the tables only to find this in the ASPStateTempApplications table:
AppId AppName
538231025 /lm/w3svc/1/root
611758131 /lm/w3svc/3/root
802488340 /lm/w3svc/4/root
-940085065 /lm/w3svc/4/root/webapp
685293685 /lm/w3svc/5/root
1210055478 /lm/w3svc/5/root/webapp
We have 2 load balanced web servers.
When I look into the ids of the web apps of both servers I see that web1 has app1 with id 4 and web2 has app1 with id 5. The same thing happens with the other app. web1 has app2 with id of 1 and web2 has app2 with id of 3.
My common sense tells me that the web servers are not sharing sessions as the session id uses the appid. Am I correct? If so why isn't this minor detailed not so obvious in the documentation? Should I make the ids match on both web servers?
The AppId is used during the creation of the SessionId, to help avoid collisions from one app to another. It's created by computing a hash of the IIS app path.
In your environment, the flow might be something like this:
Server A creates a session ID, sets it in a cookie, and stores some data in the corresponding session (a row in ASPStateTempSessions). The session ID column is created by concatenating the session ID with the AppID.
Server B receives a request with a pre-existing session ID, and uses it to find the associated session data from the ASPStateTempSessions table. If the app ID is different, the generated key will also be different.
The net effect of having multiple servers with different AppIds that are sharing the same sessions is that IDs created by one server won't collide with those from another server, and machines with different AppIds won't see each other's sessions.
Related
I have 2 application (websites) on one IIS and which is calling same remote database. Is there any thing in SQL server which will give me in stored procedure that who is calling :) ?
APP_NAME() returns the application name for the current session if set by the application. An another way of identifying the app is to log the app name through the CRUD operation , so that an additional field will be added in the tables to hold the app name.
You need to modify your connection strings and add Application Name
Data Source=myServer;
Initial Catalog=myDB;
User Id=myUsername;
Password=myPassword;
Application Name=myApp;
Now when you query sys.processes,program name will be application name
References:
http://johnnycoder.com/blog/2006/10/24/take-advantage-of-application-name/
https://www.connectionstrings.com/sql-server/
Check this thread if you are using VB.NET:
How to set "Application Name" in ADODB connection string
if not above will work
I am trying to connect to a SSAS Cube which uses windows authentication
My web application is stored on a seperate server the SQL Analysis Instance (lets says ServerWebApp) and the SSAS Cube is on ServerCUBE
OLAPCon = New AdomdConnection("Provider=MSOLAP.4; roles=Administrator; Integrated Security=SSPI; Persist Security Info=True; EffectiveUserName=<Domain\Username>; " _
& " Initial Catalog=<DBName>; Data Source=<ServerCUBE>; ")
As SSAS uses Windows authentication I have tried to impersonate my windows login by specifing EffectiveUserName however, this doesn't seem to work as I am getting the follow error:
Either the user, Domain\ServerWebApp, does not have access to the <DBName> database, or the database does not exist.
As you can see it is using the web apps login ID not my windows ID
How would I impersonate my windows ID in the SSAS ADOMD connection string?
This is what tripped me up when I used EffectiveUserName. From MSDN:
To use [the EffectiveUserName] property, the caller must have
administrative permissions in Analysis Services.
You need to configure the IIS server first by creating an Application pool first. Then you need to point this pool to the local path ( folder in C drive) which consists of msmdpump.dll and msmdpump files. Edit msmdpump file using notepad (remove localhost name and replace it with your SQL analysis server name). Provide the username of server name in place of domain\username.
I have published a web application to an IIS web server, but prior to doing this everything was working, and now it is not.
Access to the SQL Server 2008 is via User ID and Password in the connection string Persist Security Info = true. There is no windows authentication or impersonation set on the web.config, and the web application runs on our INTRANET.
The problem I am seeing is that the application loads, but when a part of the application that involves getting some data from the database it fails. Using IDataRecord as part of my mapping of data from the database to a class, the IDataRecord is showing the following:
1) Error_Number Value = 0
2) Error_Message Value = 1
after passing this into a dictionary class to see what is being returned.
Anyone out there who can shed any light on this?
Classic producer-consumer-problem.
I have x app servers which write records in a DB table (same DB).
On each server, a service is running which polls the DB table and is supposed to read the oldest entry, process it and delete it.
The issue is now that the services get into a race condition: service on server A starts reading, server B starts reading the same record. I'm a bit stuck on this...I have implemented producer-consumer so often but never across server barriers.
The server cannot talk to each other except over the DB.
Environment is SQL Server 2005 and ASP-NET 3.5.
If you pick up work in a transactional way, only one server can pick it up:
set transaction isolation level repeatable read
update top 1 tbl
set ProcessingOnServer = HOST_NAME()
from YourWorkTable tbl
where ProcessingOnServer is null
and Done = 0
Now you can select the details, knowing the work item is safely assigned to you:
select *
from YourWorkTable tbl
where ProcessingOnServer = HOST_NAME()
and Done = 0
The function host_name() returns the client name, but if you think it's safer you can pass in the hostname from your client application.
We usually add a timestamp, so you can check for servers that took too long to process an item.
I have a Sql Server 2008 Express database file that's currently being used by an ASP.NET application, and I'm not sure how to query the database without taking the website down.
I'm unable to copy the database files (.mdf and .ldf files) to another directory, since they're in use by the web server. Also, if I attach the databases to an instance of the sql server (using the 'Create Database [DB name] on (filename = '[DB filename.mdf]') for attach;' command at the sqlcmd prompt), then the application pool user becomes unable to access the database (i.e. the webpages start producing http 500 errors. I think this might have to do with the username for the application pool becoming somehow divorced from the login credentials in the sql server database).
Any suggestions? I realize this is probably a newbie question, since it seems like a rather fundamental task. However, due to my inexperience, I really don't know what the answer is, and I'm pretty stumped at this point, since I've tried a couple of different things.
Thanks!
Andrew
if I attach the databases to an instance of the sql server (using the 'Create Database [DB name] on (filename = '[DB filename.mdf]') for attach;' command at the sqlcmd prompt),
Don't do this to a live database - it's attempting to be setup an MDF to be written to by two different databases...
Use Backup/Restore
As you've found, Attach/ReAttach requires the database to be offline - use the Backup/Restore functionality:
MSDN: Using SSMS to Backup the Database
MSDN: Using SSMs to Restore the Backup
Be aware that the backup/restore doesn't maintain logins (& jobs if you have any associated with the database) - you'll have to recreate & sync if using an account other than those with uber access.
Maybe Linked Server would work?
Another alternative would be to setup another SQL Server Express/etc instance on a different box, and use the Linked Server functionality to create a connection to the live/prod data. Use a different account than the one used for the ASP application...