1

I am building winForm application, and i try to make a connection function for mssql Server but SqlConnection open/close always show "CS7069 C# Reference to type 'Component' claims it is defined in 'System', but it could not be found" how could I fix this issue?

 public class SQLAPI
{
    SqlConnection cn;

    Boolean openConnect()
    {
        bool rtn = false;
        try
        {
            cn = new SqlConnection("server=localhost;database=testDB;UID=ad;PWD=1234");
            cn.Open();
        }
        catch (Exception e)
        {

        }        
        return rtn;
    }

    void closeConnect()
    {
        try {
            cn.Close();
        }
        catch (Exception e)
        { }
    }

}
NeilLin
  • 195
  • 3
  • 11
  • Are the database credentials Windows. If so do not use UID and PWD.. Instead use Trusted_Connection=True; (see https://www.connectionstrings.com/sql-server/). also open up SQL Server Management Studio and get the instead of the data base which is in the login window. You need localhost/{instance} – jdweng Nov 13 '18 at 18:13
  • cn.Open/ cn.Close show the message before compile.... – NeilLin Nov 14 '18 at 02:33
  • The error is : ERROR_TS_INCOMPATIBLE_SESSIONS, The target session is incompatible with the current session (see : https://learn.microsoft.com/en-us/windows/desktop/debug/system-error-codes--6000-8199-). I don't thing your project (and reference projects) go completely recompiled due to dependencies in the compiler. I would make a copy of the project bin folder and then delete to force all the code to get recompiled. See : https://stackoverflow.com/questions/36723359/vs2015-c-sharp-interactive-error-cs7069-reference-to-type-object-claims-it-i – jdweng Nov 14 '18 at 10:31

0 Answers0