problem with sql connection
-
lundi 12 mars 2012 01: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
Toutes les réponses
-
lundi 12 mars 2012 02:01ModérateurTry catalog = [11] -- just a shot in the dark.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
lundi 12 mars 2012 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
- Proposé comme réponse Richard Douglas jeudi 15 mars 2012 16:20
- Marqué comme réponse KJian_ lundi 19 mars 2012 05:33

