คำตอบ problem with sql connection

  • 12 มีนาคม 2555 1:20
     
     

    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

ตอบทั้งหมด

  • 12 มีนาคม 2555 2:01
    ผู้ดูแล
     
     
    Try catalog = [11] -- just a shot in the dark.

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


    My blog

  • 12 มีนาคม 2555 15:13
     
     คำตอบ มีโค้ด

    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

    • เสนอเป็นคำตอบโดย Richard Douglas 15 มีนาคม 2555 16:20
    • ทำเครื่องหมายเป็นคำตอบโดย KJian_ 19 มีนาคม 2555 5:33
    •