Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why cookies expires when I restart SQL server?

I have set simple cookies using classic asp e.g. <%response.cookies("user")="A"%>. As I read in this Q/A, such cookies just rely on domain name and nothing else.

I have tested when I stop and start SQL server in my server, the logged in users are signed out. Also I had same experience when I have upgraded SQL server from 2012 to 2014. (I don't use ASP session and only set cookie to identify users).

My exact question is what parameters has the effect on the cookies lifetime? IIS? Application pool? Domain Name? SQL SERVER? IP address? and if it depends on these factors, how should I create a cookies which just relies on URL address?

EDIT after 1 year: I don't face the same problem when I restart SQL server after 1 year that I wrote this question. I mean this was not a permanent problem. It might depended on a special error as Jeroen said in comments or a special configuration on the server. So if you want to answer this question you may just guess what was the problem and I can not test it anymore to accept an answer as the exact answer to this question. With regards.

like image 851
Ali Sheikhpour Avatar asked Jun 17 '18 15:06

Ali Sheikhpour


People also ask

What happens when you restart SQL Server?

When we restart SQL server, we get all the memory back to the server OS, completely clean plan cache and wipe out all tempdb. That mean: To take back the memory from Windows OS will take a while. During that period, SQL server will read a lot of data from the disc and upload data back into the memory.

How do you restart a database?

Start, stop, pause, resume, or restart an instance of the Database Engine. In Object Explorer, connect to the instance of the Database Engine, right-click the instance of the Database Engine you want to start, and then select Start, Stop, Pause, Resume, or Restart.


1 Answers

In an asp.net web-application, you can set the session provider in the web.config file:

<sessionState 
            mode="SQLServer"
            sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strongpassword>"
            cookieless="false" 
            timeout="20" 
    />

Check if that isn't set to go onto a tempdb.

Other than that, SQL-server CANNOT have an influence on your cookie-lifetime, unless starting and stopping sql-server somehow clears the cookie-files on the machine sql-server runs on, which would be odd.

It's possible you use session-cookies, which get deleted every time you close the browser, in which case this is just a coincidence...

Cookies are a client-side technology.
They don't depend on anything on your server.
Cookies depend on the browser supporting cookies (and having them activated), the http-domain (and path, were set, and the subdomain, where set). Other than that, there can be HTTP-only cookies, session cookies, and normal cookies.

HTTP-only cookies can only be read or set on the server-side, it cannot be read by client-side scripts.

Since your repsonse is server-side, this can't be.
So the two remaining options are session-cookies (when you close your browser), or the cookie-timeout, which is either set in the cookie, or in the web.config file with forms-authentication:

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="40320" />
</authentication>
like image 172
Stefan Steiger Avatar answered Oct 29 '22 03:10

Stefan Steiger