用C/S写个软件连接远程数据库
报错:
异常详细信息: System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错) 以前安装过SQL2005 后来全部卸了在企业管理器中能正常连接到远程服务器
但是就是在软件中不能访问~提示这个错误~
软件访问本地服务器时可用。
高手解答下?
是连接的问题吗?
是的话麻烦给个连接实例~谢谢~!
结帖立即打分
在线等~
报错:
异常详细信息: System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错) 以前安装过SQL2005 后来全部卸了在企业管理器中能正常连接到远程服务器
但是就是在软件中不能访问~提示这个错误~
软件访问本地服务器时可用。
高手解答下?
是连接的问题吗?
是的话麻烦给个连接实例~谢谢~!
结帖立即打分
在线等~
确认你的SQL服务器的TCP是打开的, 而且要给它一个端口, 虽然默认的端口是1433,你也要写下去。 (这个bug,你可以去www.microsoft.com里查找)
确认你的SQL的登录时Mix mode.
------------------------------------
这个错误消息已经告诉你是远程数据库连接有错误,要去设置一下远程连接才行,看看是不是不允许远程连接。
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();
TCP/IP可以确认被打开~
问题是~~没有SQL2005~~
看清楚问题~谢谢~~
其实很可能就是你的SQL服务没有启动
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);
}
}
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
谢谢~genlinux