Solved

Cannot open SQL Express db using ADO

Posted on 2013-05-15
3
274 Views
Last Modified: 2013-05-16
I am trying to manually build a simple windows app to read data from a table located on my local machine The program errors out on the con.Open(); line.  When I try hard coding an user id and password, the same error occurs.
Error message: Cannot open database "TeamAllocation" requested by the login. The login failed...
When I bind the data source using the DataSorces wizard in VS, I am able to view the data.

What am I doing wrong?


Using:
Windows Authentication
VS 2012 Pro
SQL Server Express 2012 advanced (Fully installed… I think)
COORHS29RRDS1\SQLEXPRESS ...  

namespace WinAppCSharp01ADO
{
   
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            SqlConnection con = new SqlConnection("data source=.; database=TeamAllocation; integrated security=SSPI");
            SqlCommand cmd = new SqlCommand("Select * from EmployeeDetail", con);
            con.Open();
            SqlDataReader rdr = cmd.ExecuteReader();
            BindingSource Source = new BindingSource();
            Source.DataSource = rdr;
            dataGridView1.DataSource = Source;
            con.Close();  

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
 
        }
    }
}
0
Comment
Question by:Cainfarm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 total points
ID: 39169841
Here are some alternate connection strings: http://www.connectionstrings.com/sql-server-2012  I would look at the SQL Server Native Client 11.0 OLE DB Provider strings near the bottom.  This assumes that you are on the same machine as the database server because SQL Server Native Client 11.0 is installed with the database server.  If you are not on the same machine then you will probably need to download and install the SQL Server Native Client 11.0 on your machine.
0
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 400 total points
ID: 39169889
You are not specifying the server attribute (or data source) in your  connection string
The easiest way to get the connection string is go to your existing working data source (in server explorer), select it and look at the connection string property in the properties windows, Then copy that value into your code and it will work fine.

Note:The easiest way to get the connection string is using the Server explorer window in Visual Studio (View-->Server Explorer menu) and connect to the server from that window. Then you can see the connection string in the properties of the connected server (Alt+F4 with your connection selected).
0
 

Author Closing Comment

by:Cainfarm
ID: 39171788
Connections strings.com is a great resource and may help me in the future ... Copying the Data source string that Visual Studio provided the exact syntax.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question