title: Various difficulties creating ASP.NET Session tables via aspnet_regsql.exe
body: <p>We're trying to move ASP.NET session state for one of our Azure web apps into a database, and it seems like the aspnet_regsql.exe tool is the way to go.  Unfortunately, I'm getting stuck on a few issues below. It's an Azure SQL database, and I'm connecting using the server's admin account.</p>
  
  <ul>
  <li>I initially wanted to add the session tables to our existing database, so I ran <code>.\aspnet_regsql.exe -U adminusername -P adminpassword -S servername.database.windows.net -d databasename -ssadd -sstype c</code>.  Which throws the exception <em>"Database 'databasename' already exists. Choose a different database name"</em></li>
  <li>Omitting the database name and running it again throws the exception: <em>"Execution Timeout Expired"</em> after about 30 seconds, which is just the default for SqlCommand.CommandTimeout. This occurs while executing the "CREATE DATABASE" command. I tried creating a database manually, and it takes about 50 seconds for some reason. This database is S0 tier and is not under any load</li>
  <li>Running aspnet_regsql again on the already-created database (because it's idempotent, right?) leads to the "Database already exists" error, as does pre-creating an empty database for it to start from.</li>
  <li>There's no flag that lets me increase the timeout, and I can't set command timeout using the -C (connection string) flag</li>
  <li>Adding the -sqlexportonly flag to generate a script and just running that directly doesn't work either (yes, I know I'm not supposed to run InstallSqlState.sql directly). It throws a whole load of error messages saying things like:
  
  <ul>
  <li><code>Reference to database and/or server name in 'msdb.dbo.sp_add_job' is not supported in this version of SQL Server.</code></li>
  <li><code>USE statement is not supported to switch between databases.</code></li>
  <li>Which makes me think this script might have some issues with an Azure SQL database...</li>
  </ul></li>
  </ul>
  
  <p>Does anyone have any ideas?</p>
  
  <p>Update:</p>
  
  <p>It looks like all the errors involving 'msdb' are related to removing and re-adding a database job called 'Job_DeleteExpiredSessions'.  Azure SQL doesn't support database jobs, so the only options I can see are </p>
  
  <ol>
  <li>Run SQL on a VM instead (vastly more expensive, and I'd rather stick with the platform services than have to manage VMs)</li>
  <li>Implement one of those "Elastic Job Agents"</li>
  <li>Perhaps move the same functionality elsewhere (e.g. a stored proc)?</li>
  </ol>