Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Administering
»
CONNECTING TO SQL SERVER THROUGH VISUAL...
CONNECTING TO SQL SERVER THROUGH VISUAL STUDIO
Rate Topic
Display Mode
Topic Options
Author
Message
SQLCHILD
SQLCHILD
Posted Friday, February 11, 2011 4:40 AM
SSC 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
Grant Fritchey
Grant Fritchey
Posted Friday, February 11, 2011 6:09 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:40 PM
Points: 13,380,
Visits: 25,164
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.