locked
SQL Database Connectivity RRS feed

  • Question

  • User211148926 posted

    Hello,

    Software installed:

    • Windows 7 x64
    • IIS 7.5
    • .NET 4.5
    • MS SQL Server 2014

    I'm getting the following error, what am I doing wrong?

    Server Error in '/' Application.


    Keyword not supported: 'server'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.ArgumentException: Keyword not supported: 'server'.

    Source Error: 

    Line 13: @{
    Line 14: 	
    Line 15: 	var row = db.Query(query);
    Line 16: }
    Line 17: 


    Source File: c:\IIS\www\index.cshtml    Line: 15 

    Stack Trace: 

    [ArgumentException: Keyword not supported: 'server'.]
       System.Data.SqlServerCe.SqlCeConnectionStringBuilder.set_Item(String keyword, Object value) +838
       System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) +2099460
       System.Data.SqlServerCe.SqlCeConnectionStringBuilder..ctor(String connectionString) +271
       System.Data.SqlServerCe.SqlCeConnection.set_ConnectionString(String value) +301
       WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(String connectionString) +324
       WebMatrix.Data.Database.EnsureConnectionOpen() +32
       WebMatrix.Data.<QueryInternal>d__0.MoveNext() +79
       System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +536
       System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
       WebMatrix.Data.Database.Query(String commandText, Object[] parameters) +139
       ASP._Page_index_cshtml.Execute() in c:\IIS\www\index.cshtml:15
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
       System.Web.WebPages.WebPage.ExecutePageHierarchy() +376
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +157
       System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +288
    

     


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

    This is my index.cshtml:

    @{ 
        var db = Database.Open("benkyo_db");
        var query = "SELECT * FROM Products";
    }
    
    <!DOCTYPE html PUBLIC "-//W3C//Dli HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dli">
    <html lang="en">
    <head>
    	<title>Benkyo Killer</title>
    </head>
    <body>
    
    @{
    	
    	var row = db.Query(query);
    }
    
    :(
    
    </body>
    </html>

    This is my web.config:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    
      <connectionStrings>
        <add name="benkyo_db"  connectionString="Server=RAUL-PC\SQLEXPRESS;Database=benkyo;Trusted_Connection=True;" />
      </connectionStrings>
      
      <system.webServer>
        <directoryBrowse enabled="true" />
      </system.webServer>
    
    </configuration>

    Thanks in advance.

    Tuesday, January 20, 2015 1:40 PM

Answers

  • User-821857111 posted

    Add the providerName to the connection string:

    <add name="benkyo_db"  connectionString="Server=RAUL-PC\SQLEXPRESS;Database=benkyo;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 20, 2015 3:39 PM
  • User-821857111 posted

    Login failed for user 'IIS APPPOOL\ASP.NET v4.0'

    You need to add that user to as a login with db_datareader and db_datawriter permissions to the database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 21, 2015 2:14 AM

All replies

  • User-821857111 posted

    Add the providerName to the connection string:

    <add name="benkyo_db"  connectionString="Server=RAUL-PC\SQLEXPRESS;Database=benkyo;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 20, 2015 3:39 PM
  • User211148926 posted

    That got rid of the previous error, thanks, but now I'm getting this:

    Server Error in '/' Application.


    The SELECT permission was denied on the object 'Products', database 'benkyo', schema 'dbo'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.Data.SqlClient.SqlException: The SELECT permission was denied on the object 'Products', database 'benkyo', schema 'dbo'.

    Source Error: 

    Line 13: @{
    Line 14: 	
    Line 15: 	var row = db.Query(query);
    Line 16: }
    Line 17: 


    Source File: c:\IIS\www\index.cshtml    Line: 15 

    Stack Trace: 

    [SqlException (0x80131904): The SELECT permission was denied on the object 'Products', database 'benkyo', schema 'dbo'.]
       System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +717
       System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4515
       System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61
       System.Data.SqlClient.SqlDataReader.get_MetaData() +134
       System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6563001
       System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +6565639
       System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +586
       System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +104
       System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +288
       System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +171
       WebMatrix.Data.<QueryInternal>d__0.MoveNext() +234
       System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +536
       System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
       WebMatrix.Data.Database.Query(String commandText, Object[] parameters) +139
       ASP._Page_index_cshtml.Execute() in c:\IIS\www\index.cshtml:15
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
       System.Web.WebPages.WebPage.ExecutePageHierarchy() +376
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +157
       System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +288
    Tuesday, January 20, 2015 3:56 PM
  • User-821857111 posted

    Are you running the app from IIS? If so, I suspect the user account that Windows is using to connect to the database is the application pool that your app is running under in IIS. You need to give that account permission to read data (and probably write it too). You can do that from Sql Server Management Studio. Navigate to the database, then expand the Security » Users node and find the user account. Then right click and choose Permissions. Tick db_datareader.

    Tuesday, January 20, 2015 5:16 PM
  • User211148926 posted

    Those are the only users showing and I am running the site through IIS.

    And now for some reason the error message is this -_-

    Server Error in '/' Application.


    Cannot open database "benkyo" requested by the login. The login failed.
    Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.Data.SqlClient.SqlException: Cannot open database "benkyo" requested by the login. The login failed.
    Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.

    Source Error: 

    Line 13: @{
    Line 14: 	
    Line 15: 	var row = db.Query(query);
    Line 16: }
    Line 17: 


    Source File: c:\IIS\www\index.cshtml    Line: 15 

    Stack Trace: 

    [SqlException (0x80131904): Cannot open database "benkyo" requested by the login. The login failed.
    Login failed for user 'IIS APPPOOL\ASP.NET v4.0'.]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +6573870
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +717
       System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4515
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +84
       System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +53
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +368
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +6602623
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +6603203
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +942
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1162
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +72
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +6606457
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +103
       System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +2102
       System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116
       System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1079
       System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6610951
       System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +233
       System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +278
       System.Data.SqlClient.SqlConnection.Open() +239
       WebMatrix.Data.Database.EnsureConnectionOpen() +110
       WebMatrix.Data.<QueryInternal>d__0.MoveNext() +79
       System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +536
       System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
       WebMatrix.Data.Database.Query(String commandText, Object[] parameters) +139
       ASP._Page_index_cshtml.Execute() in c:\IIS\www\index.cshtml:15
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
       System.Web.WebPages.WebPage.ExecutePageHierarchy() +376
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +157
       System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +288
    

     


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

    Tuesday, January 20, 2015 5:57 PM
  • User-821857111 posted

    Login failed for user 'IIS APPPOOL\ASP.NET v4.0'

    You need to add that user to as a login with db_datareader and db_datawriter permissions to the database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 21, 2015 2:14 AM
  • User211148926 posted

    Thank you for your help Mike,

    What I ended up doing is creating a new login, new user within this login and grant dbo permissions to this user. Also switched to SQL authentication mode.

    Again, I appreciate your time, thanks a lot!

    Wednesday, January 21, 2015 3:44 AM