asp.net - Keyword not supported: 'server(local); database' -


my web.config is

<connectionstrings>     <add name="taraznegarconnectionstring" connectionstring="data source=.;initial catalog=taraznegar;integrated security=true"       providername="system.data.sqlclient" />   </connectionstrings> 

and code:

namespace taraz {     public class dal     {         string connection = "data source=.;initial catalog=taraznegar;integrated security=true";         sqlconnection con;         sqlcommand cmd;         sqldataadapter da;         datatable dt;         public dal()         {             con = new sqlconnection();             con.connectionstring = connection;             cmd = new sqlcommand();             cmd.connection = con;             da = new sqldataadapter();             da.selectcommand=cmd;             dt = new datatable();          }         public datatable executereader(string sql)         {             connect();             da.selectcommand.connection = con;             da.selectcommand.commandtext = sql;             try             {                 da.selectcommand.executereader();             }             catch             {                 da = null;             }             disconnect();             da.fill(dt);             return dt;         }        public string excutenonquery(string sql)         {             string result=null ;             cmd.commandtext = sql;             connect();             try             {                 cmd.executenonquery();             }             catch { result = "خطا"; }             disconnect();             return result;         }         public string executescalare(string sql)         {             string result = null;             cmd.commandtext = sql;             connect();             try {                  result = cmd.executescalar().tostring();             }             catch { result = "خطا"; }             disconnect();             return result;          }          void connect()         {             if (con.state == connectionstate.closed)                 con.open();         }         void disconnect()         {             if (con.state == connectionstate.open)                 con.close();         }      } } 

and when i'm using class in project error is:

server error in '/' application.

keyword not supported: 'server(local); database'.

what's probleam?

when have connectionstring in webconfig file in application don't need create connection. should use connection. in class dal creating new connection string. instead of should use this-

string connectionstring = configurationmanager.connectionstrings["taraznegarconnectionstring"].connectionstring;  

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -