Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7891963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:45:02+00:00 2026-06-03T06:45:02+00:00

i have this this code: using System; using System.Collections.Generic; using System.Text; using NHibernate; using

  • 0

i have this this code:

using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using base_donnee;
using System.IO;

namespace TrackingUnitSimulator
{ 
    public class connection
    {
        public  ISession session ;
        public IList<simulateur> simulateurs = null;
        public IList<user> users = null;
        public IList<equipment> equipments = null;
        public IList<string> jours = null;
        public IList<int> conn_1 = null;
        public IList<int> recep_1 = null;
        public IList<int> envoi_1 = null;
        public IList<int> conn_tout = null;
        public IList<int> recep_tout = null;
        public IList<int> envoi_tout = null;
        public IList<Performance> performances = null;
        public int[] mesures = new int[100];
        public IList<int> nombres = null;
          public connection()
        {
           ISessionFactory factory;
            Configuration config = new Configuration();
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
            config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2005Dialect");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=HP-PC\\SQLEXPRESS;Initial Catalog=Simulation;Integrated Security=True;Pooling=False");
            config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");

                config.AddAssembly("base_donnee");



            factory = config.BuildSessionFactory();

            try
            {
                session = factory.OpenSession();

                try
                {
                simulateurs = session.CreateQuery(@"select e from  simulateur e ordred by e.Date").List<simulateur>();

                    users = session.CreateQuery(@"select e from user e ").List<user>();
                }
                catch (Exception ex) { File.AppendAllText(@"C:\Users\HP\Desktop\test.txt",ex.ToString());}
                equipments = session.CreateQuery(@"select e from  equipment e ").List<equipment>();
                performances = session.CreateQuery(@"select e from Performance e ").List<Performance>();
                jours = session.CreateQuery(@"select distinct e.Date from simulateur e ordred by e.Date").List<string>();
                nombres = session.CreateQuery(@"select e.Nombre_simulateur from simulateur e ordred by e.Date").List<int>();
                conn_1 = session.CreateQuery(@"select  e.temps_connection from simulateur e where e.Nombre_simulateur = 1 ").List<int>();
                recep_1 = session.CreateQuery(@"select  e.temps_reception from simulateur e where e.Nombre_simulateur = 1 ").List<int>();
                envoi_1 = session.CreateQuery(@"select  e.temps_envoi from simulateur e where e.Nombre_simulateur = 1 ").List<int>();
                conn_tout = session.CreateQuery(@"select  e.temps_connection from simulateur e  ").List<int>();
                recep_tout = session.CreateQuery(@"select  e.temps_reception from simulateur e ").List<int>();
                envoi_tout = session.CreateQuery(@"select  e.temps_envoi from simulateur e ").List<int>();
                int i = 0;
                foreach (string j in jours) {
                    IQuery query = session.CreateQuery(@"select e from simulateur e where e.Date=:j ");
                    query.SetString("j", j);
                    IList<simulateur> med = query.List<simulateur>();
                    mesures[i] = med.Count;
                    i++;
                }

            }
            catch 
            {

                session.Close();
            }
        }
        public ISession getSession(){
            return session;
        }
    }
}

and the class user.cs :

using System;
using System.Collections.Generic;
using System.Text;

namespace base_donnee
{
   public class user
    {
        public virtual string login { get; set; }
        public virtual string password { get; set; }
        public virtual string name { get; set; }
        public virtual int age { get; set; }
        public virtual string location { get; set; }
    }
}

and the class user.hbm.xml:

 <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="base_donnee">
      <class name="base_donnee.user, base_donnee" table="user">
    <id name="login" type="string"></id>
        <property name="password" type="string" />
        <property name="age" type="int" />
        <property name="location" type="string" />
        <property name="name" type="string" />
      </class>
</hibernate-mapping>

my problem is that an exception appears:
NHibernate.ADOException: could not execute query
[ select user0_.login as login3_, user0_.password as password3_, user0_.age as age3_, user0_.location as location3_, user0_.name as name3_ from user user0_ ]
[SQL: select user0_.login as login3_, user0_.password as password3_, user0_.age as age3_, user0_.location as location3_, user0_.name as name3_ from user user0_] —> System.Data.SqlClient.SqlException: Incorrect syntax near the keyword ‘user’.

i need some ideas how can i avoid this error ?and why the table user ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:45:03+00:00Added an answer on June 3, 2026 at 6:45 am

    user is a keyword in T-SQL. Because you’ve named your table user, it is clashing with the T-SQL keyword.

    You need to set auto quote:

    config.Properties["keywords"] = "auto-quote";
    

    Beyond that, your code is an absolute disaster. You’re swallowing the top-level Exception type. You have hard-coded SQL statements but you’re using NHibernate (this is rarely necessary). You’re trying to close an session after it possibly failed to open. You iterate over a list using foreach but you have a manually managed index variable i. I could go on for awhile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing {
i have this code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data;
i have this code server part: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
I have this code but I just can't understand it. using System; using System.Collections.Generic;
I have the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using
I have this code in my code behind. using System; using System.Collections.Generic; using System.Linq;
quick question really: I have this code: using System; using System.Collections.Generic; using System.Linq; using
i have the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using
i have the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using
I wrote this code to create a redis client instance using System; using System.Collections.Generic;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.