Solved

Test a SQL String Connection.

Posted on 2011-09-09
6
328 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 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now