Cannot open database “pubs” requested by the login. The login failed. Login failed for user 'ESLAM\Eslam_Nora'

StackOverflow https://stackoverflow.com/questions/8316568

Question

Hello iam trying to store sum information inside a SQL Server table , but when i run the form and turned to store the data the above runtime error appears also the the pubs database icon in SQL Server is missing the (+) sign how come ! , i wrote that code for inserting , Thanks in advance.

public partial class Add_Client : Form
{

    SqlConnection clientConnection;
    string connString;
    SqlCommand insertCommand; 

   public Add_Client()
    {
        InitializeComponent();
        connString = "Data Source=.\\INSTANCE2;Initial Catalog=pubs; Integrated security=true ";
        clientConnection = new SqlConnection();
        clientConnection.ConnectionString = connString;
    }

    private void button1_ADD(object sender, EventArgs e)
    {
         try
        {

            SqlCommand insertCommand = new SqlCommand();
            insertCommand.Connection = clientConnection;
            insertCommand.CommandText = "INSERT INTO Client_Data values(@Client_Name,@Autorization_No,@Issue_Type,@Status)";
            insertCommand.Parameters.Add("@Client_Name", SqlDbType.NVarChar, 60).Value = txt_Name.Text;
            insertCommand.Parameters.Add("@Autorization_No", SqlDbType.Int, 60).Value = txt_Auth.Text.ToString();
            insertCommand.Parameters.Add("@Issue_Type", SqlDbType.Text, 200).Value = txt_Iss.Text;
            insertCommand.Parameters.Add("@Status", SqlDbType.Text, 200).Value = txt_Iss.Text;
            //insertCommand.Parameters.Add("@Date To Memorize", SqlDbType.Date, 15).Value=Ca_Mem.se;
            insertCommand.Connection.Open();
            insertCommand.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;

        }
        finally
        {
            if (clientConnection != null)
            {
                clientConnection.Close();
            }

        }
        }
}
Was it helpful?

Solution

You use integrated security to access the database. Therefore your windows user needs to be authorized to access the database. Check the security settings for the server and the database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top