Shanthala Udupa

Shanthala Udupa

  • NA
  • 97
  • 7.1k

connecting SQL server database

Jun 9 2022 5:12 AM

Hey,

I have problem in connecting to sql server database from my android mobile application from C#.net.I am  getting following exception for connection string.

System.Data.SqlClient.SqlException: 'System.Net.Security.Native assembly:<unknown assembly> type:<unknown type> member:(null) at (wrapper managed-to-native) Interop+NetSecurityNative.ImportPrincipalName(Interop/NetSecurityNative/ 

Below is my connection string code

 try
            {
                fetchquest obj = new fetchquest();
                string servdbname = "ExamSim";
                string servname = "192.168.0.171";
                string serusername = "sa";
                string serpasswd = "Success24";
                string sqlcon = $"Data Source={servname};Initial Catalog={servdbname};User Id={serusername};Password={serpasswd};Trusted_Connection=true";
                SqlConnection sqlconn = new SqlConnection(sqlcon);
                sqlconn.Open();
                SqlDataReader dr;
                SqlCommand cmd = new SqlCommand("Select * from Questions", sqlconn);
                dr = cmd.ExecuteReader();
                if (dr.HasRows == true)
                {
                    dr.Read();
                    obj.Qid = Convert.ToInt32(dr["Qid"]);
                    obj.Qus = dr["Question"].ToString();
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
               
                throw; 
            }

 


Answers (3)