Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

CONNECTING TO SQL SERVER THROUGH VISUAL STUDIO Expand / Collapse
Author
Message
Posted Friday, February 11, 2011 4:40 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, April 14, 2011 5:36 AM
Points: 30, Visits: 63
I am using the following code to connect to sql server with visual studio. i have added the ODBC source also as my database name: PermissionsTest.
Actually when i debug the code then it gives error, but via wizards it is connecting to sql server.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.Sql;


namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SqlConnection myconn = new SqlConnection();
myconn.ConnectionString =
"Data Source =PERMISSIONSTEST;User ID=a;Password=a_password;app=Microsoft® Visual Studio® 2005;wsid=A-9";
myconn.Open();

SqlCommand cmd = new SqlCommand("select * from accountinfo",myconn);

SqlDataReader myreader = cmd.ExecuteReader();

myreader.Read();

}

}
}

IT GIVES ERROR:
SqlException was unhandled
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

It gives this error on the line : myconn.Open()
Post #1062471
Posted Friday, February 11, 2011 6:09 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 11:43 AM
Points: 15,446, Visits: 27,837
Is this the name of your server: PERMISSIONSTEST? Does it have an instance name?

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1062504
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse