Answered problem with sql connection

  • Monday, March 12, 2012 1:20 AM
     
     

    hello.

    i downloaded microsoft vistual studio 2010 and sql server 2012.

    i created a database(management studio) named ''11'' and i am trying to connect a windows form with this database but i have a problem

    here is the code

    SqlConnection con = new SqlConnection();
            private void button1_Click(object sender, EventArgs e)
            { 

    con.ConnectionString = "server=.\\SQLEXPRESS;initial catalog=11;Integrated Security=true";
                    con.Open();
                    Form2 form = new Form2();
                    form.Show();
                 
               
            }

    when i click button1 i have the following error Cannot open database "11" requested by the login. The login failed.
    Login failed for user 'kosder13-PC\kosder13'

    if i change the ''11'' with the ''master'' which is a database i havo no errors.

    it is necessary to add to project the 11.mdf file or no?

    i tried everything

    please help

All Replies

  • Monday, March 12, 2012 2:01 AM
    Moderator
     
     
    Try catalog = [11] -- just a shot in the dark.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

  • Monday, March 12, 2012 3:13 PM
     
     Answered Has Code

    Hello,

    While Naomi may be correct (as a rule you shouldn't start database names with a number), you don't have a connection issue at all as shown by the successful connection when using master as your initial database context.

    What you do have is either a permissions issue, naming convention*, or database that doesn't actually exist in the instance, of which I'm leaning toward the latter.

    What is the result of the following:

    SELECT [Name] FROM sys.databases

    *Naming convention as based on rules for identifiers which specify that your name does not follow the rules and must be delimited (what Naomi has pointed out)
    http://technet.microsoft.com/en-us/library/ms175874.aspx

    -Sean

    • Proposed As Answer by Richard Douglas Thursday, March 15, 2012 4:20 PM
    • Marked As Answer by KJian_ Monday, March 19, 2012 5:33 AM
    •