Monday, March 12, 2012 1:20 AM
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";
Form2 form = new Form2();
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
Monday, March 12, 2012 2:01 AMModeratorTry catalog =  -- just a shot in the dark.
For every expert, there is an equal and opposite expert. - Becker's Law
Monday, March 12, 2012 3:13 PM
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)