用C/S写个软件连接远程数据库
报错:
异常详细信息:   System.Data.SqlClient.SqlException:   在建立与服务器的连接时出错。在连接到   SQL   Server   2005   时,在默认的设置下   SQL   Server   不允许进行远程连接可能会导致此失败。   (provider:   SQL   网络接口,   error:   26   -   定位指定的服务器/实例时出错) 以前安装过SQL2005 后来全部卸了在企业管理器中能正常连接到远程服务器
但是就是在软件中不能访问~提示这个错误~
软件访问本地服务器时可用。
高手解答下?
是连接的问题吗?
是的话麻烦给个连接实例~谢谢~!
结帖立即打分
在线等~

解决方案 »

  1.   

    确认你链接到的是你的SQL2000而不是SQL2005 Express(这和VS2005一起安装的)。
    确认你的SQL服务器的TCP是打开的, 而且要给它一个端口, 虽然默认的端口是1433,你也要写下去。 (这个bug,你可以去www.microsoft.com里查找)
    确认你的SQL的登录时Mix mode.
      

  2.   

      System.Data.SqlClient.SqlException:       在建立与服务器的连接时出错。在连接到       SQL       Server       2005       时,在默认的设置下       SQL       Server       不允许进行远程连接可能会导致此失败。       (provider:       SQL       网络接口,       error:       26       -       定位指定的服务器/实例时出错)   
    ------------------------------------
    这个错误消息已经告诉你是远程数据库连接有错误,要去设置一下远程连接才行,看看是不是不允许远程连接。
      

  3.   

    不会是连接串错误吧?using System.Data; 
    using System.Data.SqlClient; ... string strConnection="user id=sa;password=;"; strConnection+="initial catalog=Northwind;Server=YourSQLServer;"; 
    //initial catalog=Northwind,本句可以写成"Database=Northwind"
    /*Server=YourSQLServer
    如果使用的是本地数据库且定义了实例名,则可以写为"Server=(local)\实例名";如果是远程服务器,则将"(local)"替换为远程服务器的名称或IP地址.*/
    strConnection+="Connect Timeout=30"; 
    /*如果你的SQL Server设置为Windows登录,那么在这里就不需要使用"user id"和"password"这样的方式来登录,而需要使用"Trusted_Connection=SSPI"来进行登录*/
    SqlConnection objConnection=new SqlConnection(strConnection); ... objConnection.Open(); 
    objConnection.Close(); 
      

  4.   

    1楼~2楼~已经说了~企业管理器中能连接到远程服务器~端口也同步调整为1433~
    TCP/IP可以确认被打开~
      

  5.   

    http://hi.baidu.com/atmo/blog/item/ef72dc824adbb7be6d811955.html很详细...按照步骤一步步地做,我前一段时间也遇到这个问题,看看我的帖子.http://topic.csdn.net/u/20080217/17/d94bd2fd-bea6-4d6a-83e9-aeee8e75c219.html
      

  6.   

    楼上这位~~很好很强大~~
    问题是~~没有SQL2005~~
    看清楚问题~谢谢~~
      

  7.   

    问题很简单,与SQL2005无关,曾遇到过
    其实很可能就是你的SQL服务没有启动
      

  8.   

    在服务器网络实用工具中确定已经启用了TCP/IP协议了,如果启用了还是不行的话,那就应该是版本的问题了,那就在远程的SQLserver上打上sp3补丁应该就可以了
      

  9.   

    SP3补丁打了~~TCP/IP也启用了~~企业管理器可以远程连接~但是软件中不能连接~
      

  10.   

     ClassInterface.IFunctions myDBFunction = null;
            public Form1()
            {
                InitializeComponent();
            }        private void btnConnect_Click(object sender, EventArgs e)
            {
                //MessageBox.Show("I am above to connect to the server....");
                TcpClientChannel tcc = new TcpClientChannel();
                ChannelServices.RegisterChannel(tcc,true);            myDBFunction = (ClassInterface.IFunctions)Activator.GetObject(typeof(ClassInterface.IFunctions), "tcp://127.0.0.1:8888/Functions");
                //
                //display here.
                ClassInterface.dsFSA dt = myDBFunction.GetFSATable();            dgvDisplay.DataSource = dt;
                dgvDisplay.DataMember = "tblFSAQuote";
            }        private void btnSearch_Click(object sender, EventArgs e)
            {
                if (myDBFunction != null)
                {
                    try
                    {
                        ClassInterface.FSAItem fi = myDBFunction.GetSingleFSAItem(txtItemNo.Text);
                        if (fi != null)
                        {
                           
                            MessageBox.Show(fi.ItemNO + "\n" + fi.Description + "\n" + fi.Units + "\n" + fi.Size + "\n" + fi.Price);
                            //dgvDisplay.Rows.Add(new object[] { fi.ItemNO, fi.Description, fi.Units, fi.Size, fi.Price });
                        }
                        else
                        {
                            MessageBox.Show("Sorry, there is not record found for this ItemID");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
    ---------------------------------------------------
     private void btnStart_Click(object sender, EventArgs e)
            {
                //for the server, it is going to use the port 8888 as the communication port.
                //for the server, you also can put it on a HTTP server, 
                //but I don't have one, and I am using TCP as the communiction type. right now.
                try
                {
                    TcpServerChannel tsc = new TcpServerChannel(8888);                ChannelServices.RegisterChannel(tsc,true);                RemotingConfiguration.RegisterWellKnownServiceType(typeof(DatabaseFunctions.Function), "Functions", WellKnownObjectMode.SingleCall);                lblOutput.Text = "Server is up!";
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
      

  11.   

    这里有一些文档,楼主查查看
    http://blog.csdn.net/goody9807/archive/2004/12/03/203087.aspx
    http://blog.joycode.com/uestc95/archive/2004/06/29/26008.aspx
    http://davidullua.cnblogs.com/archive/2005/09/16/238252.html
    http://www.cnblogs.com/tutuya/archive/2006/08/07/470080.html
    http://www.cnblogs.com/VitoriaTang/archive/2007/02/06/641731.html
      

  12.   

    问题已解决~结帖~
    谢谢~genlinux