dimanche 1 mai 2016

asp.net c# login webpage error

i got the following problem:

Im making a website using asp.net and c# and in the very first page is the login, the HTML is basically 2 textfields and 1 button, wich request the following function:

protected void Button1_Click(object sender, EventArgs e)
     {

         ServicioIS.Service1SoapClient objeto = new ServicioIS.Service1SoapClient();
          string a = ci.Value.ToString();
          string b = pass.Value.ToString();
          // bool x = objeto.Log(a,b);
          bool flag = false;
          SqlConnection con = new SqlConnection();
          con.ConnectionString = "Server=.;database=Proyecto.mdf;user=;password=";
          con.Open();
          string check = "SELECT COUNT(*) FROM Admin WHERE login ='" + a + "'";
          SqlCommand com = new SqlCommand(check, con);
          int cont = Convert.ToInt32(com.ExecuteScalar().ToString());
          con.Close();
          if (cont == 1)
          {
              con.Open();
              string checkpass = "SELECT pass FROM Admin WHERE login = '" + a + "'";
              SqlCommand ds = new SqlCommand(checkpass, con);
              string contra = ds.ExecuteScalar().ToString().Replace(" ", "");
              con.Close();
              if (a == contra)
              {
                  flag = true;
              }
          }
           if (flag)
           {
               Response.Write("Contraseña Correcta");
           }
           else
           {
               Response.Write("usuario o contraseña invalidos");
           }


     }

the error and the stack trace is the following:

Line 31:               SqlConnection con = new SqlConnection();
Line 32:               con.ConnectionString = "      "Server=.;database=Proyecto.mdf;user=;password=";
Line 33:               con.Open();
Line 34:               string check = "SELECT COUNT(*) FROM Admin WHERE   login ='" + a + "'";
Line 35:               SqlCommand com = new SqlCommand(check, con);

Source File: c:\Users\Fabrizio\Desktop\Nueva carpeta     (2)\ProyectoIS\WebAppIS\WebAppIS\Interface\Login.aspx.cs    Line: 33 

Stack Trace: 


[SqlException (0x80131904): Login failed for user ''.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,     Boolean breakConnection, Action`1 wrapCloseInAction) +5347119
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject  stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand   cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,   TdsParserStateObject stateObj, Boolean& dataReady) +1693
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +69
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +30
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +317
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +892
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +311
  System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +646
 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278
 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1057
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196
 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110
System.Data.SqlClient.SqlConnection.Open() +96
WebAppIS.Interface.Login.Button1_Click(Object sender, EventArgs e) in  c:\Users\Fabrizio\Desktop\Nueva carpeta (2)\ProyectoIS\WebAppIS\WebAppIS\Interface\Login.aspx.cs:33
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9627718
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,   String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

PD: im using Visual Studio 2012 if it makes it any easier to fix it :)




Aucun commentaire:

Enregistrer un commentaire