自己数据库中的SQL Session状态服务器

时间:2015-11-20 12:18:43

标签: c# sql-server

我创建了一个网站并将其上传到我的托管服务器(一些小型托管服务提供商)。它运行良好,但会话存在问题;它不断登出我的用户。

它发生在完全随机的,所以我打电话给提供商,询问我的网站托管在哪种服务器。他们告诉我这是一个共享托管IIS服务器场。所以发生的事情是负载均衡器将我的会话重新路由到另一台服务器,所以我的会话丢失了,我得到了一个登录屏幕。

要解决此问题,我需要使用会话状态服务或SQL会话状态数据库。

提供程序表示无法在服务器场中运行专用的会话状态服务,因此为我留下了SQL会话状态数据库选项。

为此,我需要在我的SQL Server上运行“aspnet_regsql”工具,但是当我这样做时,我收到此错误:

Microsoft (R) ASP.NET SQL Registration Tool version 4.0.30319.33440
Administrative utility to install and uninstall ASP.NET features on a SQL server.
Copyright (C) Microsoft Corporation. All rights reserved.


Start adding session state.

.
An error occurred during the execution of the SQL file 'InstallSqlState.sql'. The SQL error number is 262 and the SqlException message is: CREATE DATABASE permission denied in database 'master'.
SQL Server: ................
Database: aspnetdb
SQL file loaded:
InstallSqlState.sql

Commands failed:

/* Create and populate the session state database */

IF DB_ID(N'ASPState') IS NULL BEGIN
    DECLARE @cmd nvarchar(500)
    SET @cmd = N'CREATE DATABASE [ASPState]'
    EXEC(@cmd)
    END

    SQL Exception:
    System.Data.SqlClient.SqlException (0x80131904): CREATE DATABASE permission denied in database 'master'.
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
    at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj, Boolean& dataReady)
    at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
    at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
    at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
    at System.Web.Management.SqlServices.ExecuteFile(String file, String server, String database, String dbFileName, SqlConnection connection, Boolean sessionState, Boolean isInstall, SessionStateType sessionStatetype)
    ClientConnectionId:............................................
    Error Number:262,State:1,Class:14

所以我没有权限创建自己的数据库,因此无法创建专用的“ASPState”数据库。

有人可以帮忙吗?有没有办法在分配给我的帐户的数据库上安装SessionState服务,即专用ASPState数据库的instat?

1 个答案:

答案 0 :(得分:0)

使用aspnet_regsql命令行实用程序,然后指定连接字符串和数据库名称以创建表,如果服务器中存在db name,它不会创建数据库并将创建表 [Msdn link] https://msdn.microsoft.com/en-us/library/ms229862.aspx

例如命令行: aspnet_regsql -A all -C“Data Source =。\ SQLEXPRESS; Integrated Security = True;” -d yourbusinessdbname