Results 1 to 40 of 40

Thread: Login failed.The login is from an untrusted domain and cannot be used..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Login failed.The login is from an untrusted domain and cannot be used..

    Hello..

    I have created a login form for my project,I have searched on google and found out to make the integrated security=false but it still doesnt work,and when i install it on another pc it shows me the error :


    Code:
    XCEPTION      : Handled
    MESSAGE        : Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
    SOURCE         : .Net SqlClient Data Provider
    TARGETSITE     : Void .ctor(System.Data.ProviderBase.DbConnectionPoolIdentity, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SqlCredential, System.Object, System.String, System.Security.SecureString, Boolean, System.Data.SqlClient.SqlConnectionString, System.Data.SqlClient.SessionData, System.Data.ProviderBase.DbConnectionPool, System.String, Boolean, System.Data.SqlClient.SqlAuthenticationProviderManager)
    STACKTRACE     : 
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
       at DG.DentneD.LoginForm.button1_Click(Object sender, EventArgs e) in C:\Users\windows\Desktop\New folder (19)\dentned-master\DentneD\LoginForm.cs:line 56
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    and here is my LoginForm code
    Code:
                doctors.last_login = DateTime.Now;
                string srcConnString = null;
                var csBuilder = new SqlConnectionStringBuilder(srcConnString);
                csBuilder.Remove("Integrated Security");
                csBuilder.UserID = "sa";
                csBuilder.Password = "sasa";
                var connString = csBuilder.ToString();
                SqlConnection sqlcon = new SqlConnection("data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;user=sa;password=sasa;MultipleActiveResultSets=True;App=EntityFramework"");
                string query = "Select * from dbo.doctors Where doctors_username = '" + txtUsername.Text.Trim() + "' and doctors_password = '" + txtPassword.Text.Trim() + "'";
                SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
    
    
                DataTable dbdoc = new DataTable();
                //sda.Fill(dbdoc);
                if (dbdoc.Rows.Count == 1) 
    
                {
                    FormMain objfrmMain = new FormMain();
                    this.Hide();
                    if(dbdoc.Rows[0][8].ToString()!="admin")
                       
                    {
                        objfrmMain.MainMenuStrip.Items[0].Visible = false;
                        objfrmMain.MainMenuStrip.Items[2].Visible = false;
                        objfrmMain.MainMenuStrip.Items[3].Visible = false;
                        objfrmMain.MainMenuStrip.Items[4].Visible = false;
                        objfrmMain.MainMenuStrip.Items[5].Visible = false;
                        objfrmMain.MainMenuStrip.Items[8].Visible = false;
                        
    
                    }
                    objfrmMain.Show();
    
                }
                else
                {
                    MessageBox.Show("Username-i ose passwordi eshte gabim !!!!!!!!!!!!!!!!!!!");
                }
    
                
                         
            }

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    You are using csBuilder to build a partial connection string (with no server or database info), and then assign it to connString... which you don't use (which means all of that code is effectively pointless).

    You have a full connection string on the line that declares/sets the variable sqlcon , and that line includes integrated security=True; . change the True to False.


    By the way, applications should very rarely (if ever) use the sa account, because it has full permissions. It is much better to create a new user for your application to use, and only assign appropriate permissions to it.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    i have tryed integrated security=false but still have the same problem,i think the problem must be in sda.Fill(dbdoc);, what u supose me to do ?

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by ali3nn View Post
    i have tryed integrated security=false but still have the same problem,i think the problem must be in sda.Fill(dbdoc);, what u supose me to do ?
    Could you show us the actual connection string you are using? As si has already pointed out your code seems to have two different connection strings being used.

    If you set a breakpoint on the line
    Code:
     SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
    and in the debugger look at the inspect the sqlcon variable, what does it's ConnectionString property look like?
    Last edited by PlausiblyDamp; Jan 10th, 2019 at 02:26 PM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    My connection string :

    Code:
      <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by ali3nn
    i have tryed integrated security=false but still have the same problem,i think the problem must be in sda.Fill(dbdoc);, what u supose me to do ?
    The error message in the first post is definitely telling you the database server is refusing to let you log in, due to your connection string attempting to use a Windows login.

    Note that sda.Fill uses sqlcon to connect, so sqlcon is the issue.


    Go to http://www.connectionstrings.com/ and find yourself a valid connection string for your situation (change things like the server name and database as apt), and use it on the line that sets sqlcon.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by ali3nn View Post
    My connection string :

    Code:
      <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
      </connectionStrings>
    Oh dear... that is not what PlausiblyDamp told you to do, but in a way it is better you did this.

    That connection string is different, and includes integrated security=True


    You should work out a valid connection string (as explained in my previous post), and change it in both places.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    How should i change the code that let me in connect to it.. ?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    My connection string :

    Code:
      <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>

  10. #10
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by ali3nn View Post
    My connection string :

    Code:
      <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
      </connectionStrings>
    That looks more like a connection string that would be used by an Entity Framework model, not one you would use directly with a SqlConnection object.

    Could you please show us the current state of the code you are using or do what I asked and show us the connection string from the debugger. In fact if you could do both that would probably be even better.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Actually this project is using Entity Connection,I have 3 app.configs and they used this connection string,

    Code:
     <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
      </connectionStrings>
    and the login form i created uses the code that i already posted i think my code isnt right.. how should be a login form with entity? should they use the same connstring?

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Actually this project is using Entity Connection,I have 3 app.configs and they used this connection string,

    Code:
     <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
      </connectionStrings>
    and the login form i created uses the code that i already posted i think my code isnt right.. how should be a login form with entity? should they use the same connstring?

  13. #13
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by ali3nn View Post
    Actually this project is using Entity Connection,I have 3 app.configs and they used this connection string,

    Code:
     <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
      </connectionStrings>
    and the login form i created uses the code that i already posted i think my code isnt right.. how should be a login form with entity? should they use the same connstring?
    If you are really using that connection string then simply looking at it you will see that it has integrated security=True in there, so that certainly could be the source of the problem.

    However that has nothing to do with the code you actually posted as your original post isn't using Entity Framework. Are you sure the error is happening in the bit of code you posted? If so please show us the current version of the code, if it isn't the failing code then show us the failing code.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Yeah actually the error is in the Loginform i havent this error before i created the login form..
    here is all the code of LoginForm

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using System.Windows.Forms;
    using System.Data.Entity;
    using System.Data.Entity.SqlServer;
    
    
    
    namespace DG.DentneD
    {
    
    
    
        public partial class LoginForm : Form
        {
            public LoginForm()
            {
                InitializeComponent();
            }
    
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void LoginForm_Load(object sender, EventArgs e)
            {
                label4.Text = DateTime.Now.ToString();
            }
    
            private void label3_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void button1_Click(object sender, EventArgs e)
    
    
            {
    
    
                string srcConnString = null;
                var csBuilder = new SqlConnectionStringBuilder(srcConnString);
                csBuilder.Remove("Integrated Security");
                csBuilder.UserID = "sa";
                csBuilder.Password = "sasa";
                var connString = csBuilder.ToString();
                SqlConnection sqlcon = new SqlConnection("data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;user=sa;password=sasa;MultipleActiveResultSets=True;App=EntityFramework&quot;");
                string query = "Select * from dbo.doctors Where doctors_username = '" + txtUsername.Text.Trim() + "' and doctors_password = '" + txtPassword.Text.Trim() + "'";
                SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
               
    
                DataTable dbdoc = new DataTable();
                sda.Fill(dbdoc);
                
                if (dbdoc.Rows.Count == 1) 
    
                {
                    FormMain objfrmMain = new FormMain();
                    this.Hide();
                    if(dbdoc.Rows[0][8].ToString()!="admin")
                       
                    {
                        objfrmMain.MainMenuStrip.Items[0].Visible = false;
                        objfrmMain.MainMenuStrip.Items[2].Visible = false;
                        objfrmMain.MainMenuStrip.Items[3].Visible = false;
                        objfrmMain.MainMenuStrip.Items[4].Visible = false;
                        objfrmMain.MainMenuStrip.Items[5].Visible = false;
                        objfrmMain.MainMenuStrip.Items[8].Visible = false;
                        
    
                    }
                    objfrmMain.Show();
    
                }
                else
                {
                    MessageBox.Show("Wrong username or password !!!!!!!!!!!!!!!!!!!");
                }
    
                
                         
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void label2_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label1_Click(object sender, EventArgs e)
            {
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void label4_Click(object sender, EventArgs e)
            {
                label4.Text = DateTime.Now.ToString();
            }
    
            private void label5_Click(object sender, EventArgs e)
            {
    
            }
        }
    }

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Yeah actually the error is in the Loginform i havent this error before i created the login form..
    here is all the code of LoginForm

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using System.Windows.Forms;
    using System.Data.Entity;
    using System.Data.Entity.SqlServer;
    
    
    
    namespace DG.DentneD
    {
    
    
    
        public partial class LoginForm : Form
        {
            public LoginForm()
            {
                InitializeComponent();
            }
    
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void LoginForm_Load(object sender, EventArgs e)
            {
                label4.Text = DateTime.Now.ToString();
            }
    
            private void label3_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void button1_Click(object sender, EventArgs e)
    
    
            {
    
    
                string srcConnString = null;
                var csBuilder = new SqlConnectionStringBuilder(srcConnString);
                csBuilder.Remove("Integrated Security");
                csBuilder.UserID = "sa";
                csBuilder.Password = "sasa";
                var connString = csBuilder.ToString();
                SqlConnection sqlcon = new SqlConnection("data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;user=sa;password=sasa;MultipleActiveResultSets=True;App=EntityFramework&quot;");
                string query = "Select * from dbo.doctors Where doctors_username = '" + txtUsername.Text.Trim() + "' and doctors_password = '" + txtPassword.Text.Trim() + "'";
                SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
               
    
                DataTable dbdoc = new DataTable();
                sda.Fill(dbdoc);
                
                if (dbdoc.Rows.Count == 1) 
    
                {
                    FormMain objfrmMain = new FormMain();
                    this.Hide();
                    if(dbdoc.Rows[0][8].ToString()!="admin")
                       
                    {
                        objfrmMain.MainMenuStrip.Items[0].Visible = false;
                        objfrmMain.MainMenuStrip.Items[2].Visible = false;
                        objfrmMain.MainMenuStrip.Items[3].Visible = false;
                        objfrmMain.MainMenuStrip.Items[4].Visible = false;
                        objfrmMain.MainMenuStrip.Items[5].Visible = false;
                        objfrmMain.MainMenuStrip.Items[8].Visible = false;
                        
    
                    }
                    objfrmMain.Show();
    
                }
                else
                {
                    MessageBox.Show("Wrong username or password !!!!!!!!!!!!!!!!!!!");
                }
    
                
                         
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void label2_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label1_Click(object sender, EventArgs e)
            {
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void label4_Click(object sender, EventArgs e)
            {
                label4.Text = DateTime.Now.ToString();
            }
    
            private void label5_Click(object sender, EventArgs e)
            {
    
            }
        }
    }

  16. #16
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    The line
    Code:
       SqlConnection sqlcon = new SqlConnection("data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;user=sa;password=sasa;MultipleActiveResultSets=True;App=EntityFramework&quot;");
    is creating a connection string with integrated security=true still, either use the SqlConnectionStringBuilder or set the connection string directly but as si pointed out previously, you aren't using the connection string generated by the builder. Fix the connection string and it should work.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by PlausiblyDamp View Post
    The line
    Code:
       SqlConnection sqlcon = new SqlConnection("data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;user=sa;password=sasa;MultipleActiveResultSets=True;App=EntityFramework&quot;");
    is creating a connection string with integrated security=true still, either use the SqlConnectionStringBuilder or set the connection string directly but as si pointed out previously, you aren't using the connection string generated by the builder. Fix the connection string and it should work.
    Okay can u tell me how must the conn string be with SqlConnectionStringBuilder !

    Thank u!

  18. #18
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    You don't need to use SqlConnectionStringBuilder (and aren't actually using it at the moment, that code just creates a value you ignore).

    You can just use a connection string, as you are already doing in the line PlausiblyDamp quoted, you just need to put the correct values into it... and you already know that integrated security=True; is not correct. If you don't already know what your connection string should contain, then as I have said before, see post #6.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    I must use this conn string
    Code:
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    But the question is how should it be in login form.. and how to access the user and passwrd? user-type?

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    I must use this conn string
    Code:
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    But the question is how should it be in login form.. and how to access the user and passwrd? user-type?

  21. #21
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by ali3nn View Post
    I must use this conn string
    Code:
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
    But the question is how should it be in login form.. and how to access the user and passwrd? user-type?
    That connection string is specific to the Entity Framework model and won't work with a standard SqlConnection object. If you are supposed to be using Entity Framework then presumably whoever created the project has already created an entity model that uses this connection string, however without seeing your solution it is going to be difficult for anyone here to give any specific advice.

    Do you have access to the entity model in the solution (probably an edmx file)?

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by PlausiblyDamp View Post
    That connection string is specific to the Entity Framework model and won't work with a standard SqlConnection object. If you are supposed to be using Entity Framework then presumably whoever created the project has already created an entity model that uses this connection string, however without seeing your solution it is going to be difficult for anyone here to give any specific advice.

    Do you have access to the entity model in the solution (probably an edmx file)?
    Yes this is an open source project u can see the EntityModel HERE.and YES i have access to edmx file,the error is from loginForm i dont know how must the connection string for login mode?

  23. #23
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Right, that changes things quite a bit....

    If you are going to be working with that project then you really should be working with the functionality it provides or at least trying to follow it's patterns if you are going to extend things.

    A quick glance through it seems to indicate the data access is done via the DentneDModel so you would do something like this to create an instance
    Code:
    DentneDModel dentnedModel = new DentneDModel();
    I suspect something like
    Code:
    var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == "user name" && d.doctors_password == "password");
    might work as a login but it might be easier to contact the maintainer of the project and see if there is anything in the project to handle logins.

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by PlausiblyDamp View Post
    Right, that changes things quite a bit....

    If you are going to be working with that project then you really should be working with the functionality it provides or at least trying to follow it's patterns if you are going to extend things.

    A quick glance through it seems to indicate the data access is done via the DentneDModel so you would do something like this to create an instance
    Code:
    DentneDModel dentnedModel = new DentneDModel();
    I suspect something like
    Code:
    var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == "user name" && d.doctors_password == "password");
    might work as a login but it might be easier to contact the maintainer of the project and see if there is anything in the project to handle logins.


    Okay my Login form code must be like this yes


    Code:
                string srcConnString = null;
                var csBuilder = new SqlConnectionStringBuilder(srcConnString);
                csBuilder.Remove("Integrated Security");
                csBuilder.UserID = "sa";
                csBuilder.Password = "sasa";
                var connString = csBuilder.ToString();
    
                DentneDModel dentnedModel = new DentneDModel();
    
                var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == "user name" && d.doctors_password == "password");
    
                SqlConnection sqlcon = new SqlConnection("data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=FALSE ;user=sa;password=sasa;MultipleActiveResultSets=True;App=EntityFramework&quot;");
                string query = "Select * from dbo.doctors Where doctors_username = '" + txtUsername.Text.Trim() + "' and doctors_password = '" + txtPassword.Text.Trim() + "'";
                SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon);
               
    
                DataTable dbdoc = new DataTable();
                sda.Fill(dbdoc);

    Or should i remove something ??

  25. #25
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    You should be using the entity model instead of the raw sql code something more like

    Code:
    DentneDModel dentnedModel = new DentneDModel();
    var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == txtUsername.Text.Trim() && d.doctors_password == txtPassword.Text.Trim());
    instead of the code you already have.

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by PlausiblyDamp View Post
    You should be using the entity model instead of the raw sql code something more like

    Code:
    DentneDModel dentnedModel = new DentneDModel();
    var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == txtUsername.Text.Trim() && d.doctors_password == txtPassword.Text.Trim());
    instead of the code you already have.
    Aha okay but then it says the password is wrong when i use just use this line of code:

    Code:
      DentneDModel dentnedModel = new DentneDModel();
                var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == txtUsername.Text.Trim() && d.doctors_password == txtPassword.Text.Trim());

  27. #27
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by ali3nn View Post
    Aha okay but then it says the password is wrong when i use just use this line of code:

    Code:
      DentneDModel dentnedModel = new DentneDModel();
                var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == txtUsername.Text.Trim() && d.doctors_password == txtPassword.Text.Trim());
    That looks like something a lot more specific to the application itself, have you checked the user name and password against what is in the database? Is the password hashed or similar?

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Yes the username password is correct, But should we use another code or something to connect to it ?

  29. #29

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Code:
                DataTable dbdoc = new DataTable();
                //sda.Fill(dbdoc);
    
                  DentneDModel dentnedModel = new DentneDModel();
                  var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == txtUsername.Text.Trim() && d.doctors_password == txtPassword.Text.Trim());
                
                if (dbdoc.Rows.Count == 1) 
    
                {
                    FormMain objfrmMain = new FormMain();
                    this.Hide();
                    if(dbdoc.Rows[0][8].ToString()!="admin")
                       
                    {
                        objfrmMain.MainMenuStrip.Items[0].Visible = false;
                        objfrmMain.MainMenuStrip.Items[2].Visible = false;
                        objfrmMain.MainMenuStrip.Items[3].Visible = false;
                        objfrmMain.MainMenuStrip.Items[4].Visible = false;
                        objfrmMain.MainMenuStrip.Items[5].Visible = false;
                        objfrmMain.MainMenuStrip.Items[8].Visible = false;
                        
    
                    }
                    objfrmMain.Show();
    
                }
                else
                {
                    MessageBox.Show("Username-i ose passwordi eshte gabim !!!!!!!!!!!!!!!!!!!");
                }
    My code but still deosnt work!!!!!!!!!!

  30. #30
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Firstly if you are dealing with EF then the lines
    Code:
    DataTable dbdoc = new DataTable();
    //sda.Fill(dbdoc);
    are pointless and can be removed.

    However in your code you are also doing
    Code:
     if (dbdoc.Rows.Count == 1)
    which has nothing to do with the Entity Framework code and will never equal 1 as you are never loading any data into dbdoc, I suspect you should be checking if res != null but I am only really guessing.

    I would suggest you take some time to get familiar with Entity Framework and the existing project before proceeding with your own modifications. If you are modifying existing code part of the process involves learning how it does things and figuring out what the best approach should be, just hacking away and trying to force your approach into an existing project is rarely going to be a success.

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by PlausiblyDamp View Post
    Firstly if you are dealing with EF then the lines
    Code:
    DataTable dbdoc = new DataTable();
    //sda.Fill(dbdoc);
    are pointless and can be removed.

    However in your code you are also doing
    Code:
     if (dbdoc.Rows.Count == 1)
    which has nothing to do with the Entity Framework code and will never equal 1 as you are never loading any data into dbdoc, I suspect you should be checking if res != null but I am only really guessing.

    I would suggest you take some time to get familiar with Entity Framework and the existing project before proceeding with your own modifications. If you are modifying existing code part of the process involves learning how it does things and figuring out what the best approach should be, just hacking away and trying to force your approach into an existing project is rarely going to be a success.
    Hello. thank u for ur advice my friend, i searched in google about entity framework conn how it must be but i cannot find nothing*
    Here is my connection string* }
    Code:
      <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    And from this conn string that is in my app config i need to provide a conn for login form like this one but i dont know how exactly it should be

    Code:
    DentneDModel dentnedModel = new DentneDModel("connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;");
    And then i have to reach db.doctors table doc_username&password,and then
    Code:
    If user type is = admin 
    {
    
    }
    else {
    
    }
    Does somebody know how must the code be thankyou.

  32. #32
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    If you are using the model then you can just create an instance of it, you don't need to pass the connection string in. If you look at any of the other places in the project where DentneDModel is being used you can see that this is the case.

  33. #33

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Hmm.. explain a little how could it be??

    Write me a code ?

  34. #34
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    I actually gave an example of how to create an instance of the class in post #23

    As to actually validating the user name and password I suspect that is going to be a bit more difficult as the only example in that project is contained as part of the php application here and it appears to involve escaping both the username and password as part of the process.

    My PHP is not really good enough to do more than skim that code so I am not sure how much help I would be.

  35. #35

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by PlausiblyDamp View Post
    I actually gave an example of how to create an instance of the class in post #23

    As to actually validating the user name and password I suspect that is going to be a bit more difficult as the only example in that project is contained as part of the php application here and it appears to involve escaping both the username and password as part of the process.

    My PHP is not really good enough to do more than skim that code so I am not sure how much help I would be.
    Aha i really do not know how to use php login form for this project.. but all i want to do is creating a connection in my LoginForm* but it doesnt work anyway i do it.. its a little bit complicated* any of the codes doesnt work for me!

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by ali3nn View Post
    Aha i really do not know how to use php login form for this project.. but all i want to do is creating a connection in my LoginForm* but it doesnt work anyway i do it.. its a little bit complicated* any of the codes doesnt work for me!

    I have created a new loginform..

    Code here :

    Code:
                DentneDModel dentnedModel = new DentneDModel();
                var res = dentnedModel.Doctors.FirstOrDefault(d => d.doctors_username == "user name" && d.doctors_password == "password");
    And i checked the project found out this codes
    Code:
            public string doctors_username { get; set; }
    
            public string doctors_password { get; set; }
    my conn string in app.config

    Code:
    <connectionStrings>
        <add name="dentnedEntities" connectionString="metadata=res://*/Entity.Model_dentned.csdl|res://*/Entity.Model_dentned.ssdl|res://*/Entity.Model_dentned.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-Q8526KR;initial catalog=dentned;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    So do anyone knows how the code should be for the loginFORM? i added db do dataSource..!!!!!!

  37. #37
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    In your code you could try passing in a user name and password rather than just the strings "username" and "password"

  38. #38

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by PlausiblyDamp View Post
    In your code you could try passing in a user name and password rather than just the strings "username" and "password"
    Okay so do u have any idea how to do it?

  39. #39
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,474

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    You mean something like the code I showed back in #25

    I don't mean to be rude about this but how much programming experience do you have? Jumping into a large system like this one with multiple projects, EF / Repository patterns etc and trying to make changes isn't a simple or easy task and certainly not one I would have liked to do without quite a bit of experience or somebody to hand who knew the code base.

    If you don't have much experience then it might be worth spending a bit of time to learn the basics of things like EF, Linq, etc. and getting yourself familiar with design patterns such as the repository pattern.

  40. #40

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    72

    Re: Login failed.The login is from an untrusted domain and cannot be used..

    Quote Originally Posted by PlausiblyDamp View Post
    You mean something like the code I showed back in #25

    I don't mean to be rude about this but how much programming experience do you have? Jumping into a large system like this one with multiple projects, EF / Repository patterns etc and trying to make changes isn't a simple or easy task and certainly not one I would have liked to do without quite a bit of experience or somebody to hand who knew the code base.

    If you don't have much experience then it might be worth spending a bit of time to learn the basics of things like EF, Linq, etc. and getting yourself familiar with design patterns such as the repository pattern.

    I have experience but ill need little help about it,so i will try to pass the value* if it doesnt work i come back here!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width