在DELPHI 的程序代码里写设置MSSQL数据库客户端的端口(如:1433 改成 2433)?

解决方案 »

  1.   

    连接字符串中的服务器地址后面加上 ",<端口号>" 就行了如"Server,2433"
      

  2.   

    我加了,连接提示 找不到SQL服务器
      

  3.   

    服务器正常工作了吗?
    如果连接字符串没有错,就是其他地方出问题了
     Connect via an IP address:"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;" 
    (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
    adoconnection连接代码:
      if adoConnection1.Connected then
        adoConnection1.Close;
      AdoConnection1.ConnectionString := 'Provider=SQLOLEDB.1;' +
         'Persist Security Info=False;' +
         'User ID=' + edtUser.Text + ';' +
         'password=' + edtPwd.Text + ';' +
         'Initial Catalog=master;' +
         'Data Source=' + lbServer.Items[lbServer.ItemIndex] + ';';
      AdoConnection1.Open;
    如果还不行,试试
    直接在注册表中建立SQL客户端配置信息(win2000+sql2000上测试通过):首先要保证有这样的项:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo然后在这下面建立对应的服务器配置新建字符串值:名称:test,值:DBMSSOCN,test,5433
    说明:
     名称 test 对应客户端配置工具中的服务器的别名,连接服务器就用这个名称
     值 DBMSSOCN,test,5433 中,DBMSSOCN 是固定的
      test SQL服务器名或ip地址(针对tcp/ip协议),5433 是端口号这种方法是针对tcp/ip连接的,如果是其他连接方式,自己配置,然后查看注册表中的对应值