?
Solved

Cannot open database using ADO.Net

Posted on 2011-11-01
3
Medium Priority
?
395 Views
Last Modified: 2012-05-12
I am trying to run the following code.  I am get an SqlException when executing through the theConnection.Open()
          try
            {

                ConnectionStringSettings theConnectionString = ConfigurationManager.ConnectionStrings["TK70561.Properties.Settings.VideoGameStoreDB"];

                SqlConnection theConnection = new SqlConnection(theConnectionString.ConnectionString);
                Console.WriteLine(theConnectionString.ToString());
                theConnection.Open();
                if (theConnection.State == System.Data.ConnectionState.Open)
                    returnMessage = "Database Connection is Open";
            }
            catch (SqlException sqlexception)
            {
                returnMessage = sqlexception.Message;
            }
            catch (Exception exception)
            {
                returnMessage = exception.Message;
            }

My connection sting is as follows:
theConnectionString = "Data Source=COMPUTER1\SQLTEST;Initial Catalog=VidoeGames;Integrated Security=SSPI";

This is the message from the sqlException:
returnMessage      "Cannot open database \"VidoeGames\" requested by the login. The login failed.\r\nLogin failed for user 'Computer1\\user1'."      string

I am running all on the same computer.  I can login into SQL Server Management Studio using Computer1\user1.  The VideoGames Database is owned by Computer1\\user1.

Can anyone suggest what I need to check to resolve such problem.
0
Comment
Question by:tommym121
3 Comments
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 37063799
theConnectionString = "Data Source=COMPUTER1\SQLTEST;Initial Catalog=VidoeGames;Integrated Security=SSPI";

Is that correct?  (Because you write about a differently named database in the body of the question.)
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 37063807
try the full path  
EX
Data Source=C:\PROGRAM FILES\SQL SERVE\SQLTEST
0
 

Author Closing Comment

by:tommym121
ID: 37064818
Thanks.  It is a typo.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 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