connecting sql server 2005 express with visual studio

  • 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()

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply