February 11, 2011 at 4:40 am
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()
February 11, 2011 at 6:09 am
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
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply