Solved

Test a SQL String Connection.

Posted on 2011-09-09
6
343 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
[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
  • 2
6 Comments
 
LVL 5

Assisted Solution

by:zvytas
zvytas earned 100 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 400 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 400 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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…

632 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