Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Test a SQL String Connection.

Posted on 2011-09-09
6
Medium Priority
?
346 Views
Last Modified: 2012-05-12
I have a SQL Server2005 studio express  mangement Express and i have this line code in my visual studio.

how i'm able to test it in my SQL if the connection work to my database.  Please details step by step how i can test my db connection ?

here is my vstudio code  

string myConnectionString = "server=SCCAPP1;database=abc_WEB;User ID=abc;password=abcd";
0
Comment
Question by:LelloLello
  • 3
  • 2
6 Comments
 
LVL 5

Assisted Solution

by:zvytas
zvytas earned 400 total points
ID: 36511713
string myConnectionString = "server=SCCAPP1;database=abc_WEB;User ID=abc;password=abcd";
SqlConnection myConnection = new SqlConnection(myConnectionString)
try
{
  myConnection.Open();
  // connection successful
}
catch
{
  // connection failed
}
finally
{
  if (myConnection.State == ConnectionState.Open)
  {
    myConnection.Close();
  }
}
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 1600 total points
ID: 36511719
Create a throw-away project and do something like the following:

C#
try
{
    System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(myConnectionString);

    con.Open();
    con.Close();
    con.Dispose();
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
    // or if you're using a forms app
    MessageBox.Show(ex.ToString());
}

Open in new window


If you see the message, then the connection failed. You should get an indication as to why from the message printed.
0
 

Author Comment

by:LelloLello
ID: 36511814
Well i'd like to test it in my microsoft SQL Studio ? could you please advice.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1600 total points
ID: 36512086
If you are referring to SQL Server Management Studio (SSMS), then you can simply enter the appropriate details on the "Connect to Server" window (File->Connect Object Explorer).

Screenshot
Once you connect, if you cannot see the "Object Explorer," you can open by going to View->Object Explorer or by pressing the F8 key.
0
 

Author Comment

by:LelloLello
ID: 36512459
okay i'm there but i wasn't able to find that DB ? where i should look for a database=abc_WEB
0
 

Author Comment

by:LelloLello
ID: 36512460
i've logged in.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

927 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