title: Npgsql Error 42601 syntax error at or near "["
body: <p>I am getting this exception on the InitializeDataBaseConnection(). The exception is
  Npgsql.NpgsqlException was unhandled by user code. It appears that the SQL generated has square brackets for table and column names and Npgsql is not liking it. How can I get around this error?</p>
  
  <p>Here is my SimpleMembershipProvider constructor:</p>
  
  <pre><code>public SimpleMembershipInitializer()
  {
  Database.SetInitializer&lt;UsersContext&gt;(null);
  
  try
  {
      using (var context = new UsersContext())
      {
          if (!context.Database.Exists())
          {
              // Create the SimpleMembership database without Entity Framework migration schema
              ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
          }
      }
  
      WebSecurity.InitializeDatabaseConnection("MyDBContext", "UserProfile", "UserId", "UserName", autoCreateTables: false);
  }
  catch (Exception ex)
  {
       throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
  }
  }
  
  
    **Message=ERROR: 42601: syntax error at or near "["**
    Source=Npgsql
    ErrorCode=-2147467259
    BaseMessage=syntax error at or near "["
  
    Code=42601
    Detail=""
    **ErrorSql=SELECT [UserId] FROM [UserProfile] WHERE (UPPER([UserName]) = ((E'Z')))**
    File=src\backend\parser\scan.l
    Hint=""
    Line=1044
    Position=8
    Routine=scanner_yyerror
    Severity=ERROR
    Where=""
    StackTrace:
         at Npgsql.NpgsqlState.&lt;ProcessBackendResponses_Ver_3&gt;d__a.MoveNext() in C:\projects\Npgsql2\src\Npgsql\NpgsqlState.cs:line 850
         at Npgsql.ForwardsOnlyDataReader.GetNextResponseObject() in C:\projects\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:line 1173
         at Npgsql.ForwardsOnlyDataReader.GetNextRowDescription() in C:\projects\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:line 1191
         at Npgsql.ForwardsOnlyDataReader.NextResult() in C:\projects\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:line 1377
         at Npgsql.ForwardsOnlyDataReader..ctor(IEnumerable`1 dataEnumeration, CommandBehavior behavior, NpgsqlCommand command, NotificationThreadBlock threadBlock, Boolean synchOnReadError) in C:\projects\Npgsql2\src\Npgsql\NpgsqlDataReader.cs:line 1040
         at Npgsql.NpgsqlCommand.GetReader(CommandBehavior cb) in C:\projects\Npgsql2\src\Npgsql\NpgsqlCommand.cs:line 611
         at Npgsql.NpgsqlCommand.ExecuteScalar() in C:\projects\Npgsql2\src\Npgsql\NpgsqlCommand.cs:line 722
         at WebMatrix.Data.Database.QueryValue(String commandText, Object[] args)
         at WebMatrix.WebData.DatabaseWrapper.QueryValue(String commandText, Object[] parameters)
         at WebMatrix.WebData.SimpleMembershipProvider.GetUserId(IDatabase db, String userTableName, String userNameColumn, String userIdColumn, String userName)
         at WebMatrix.WebData.SimpleMembershipProvider.ValidateUserTable()
    InnerException: 
  </code></pre>