Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#关于VMWare的项目,数据库在VMWare之外_C#_Database_Sql Server 2008_Vmware - Fatal编程技术网

C#关于VMWare的项目,数据库在VMWare之外

C#关于VMWare的项目,数据库在VMWare之外,c#,database,sql-server-2008,vmware,C#,Database,Sql Server 2008,Vmware,我有一个关于VMWare的C#项目,我的数据库在VMWare之外。它在我的真实电脑上,VMWare也在同一台电脑上。我的问题是如何在我的电脑上访问我的数据库?我有这门课,但它不起作用 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.D

我有一个关于VMWare的C#项目,我的数据库在VMWare之外。它在我的真实电脑上,VMWare也在同一台电脑上。我的问题是如何在我的电脑上访问我的数据库?我有这门课,但它不起作用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;


namespace EyeCareCenter
{
    class DataBase
    {
        private string connectionstring = @"Data Source =127.0.0.1,1433 ; Network      Library=DBMSSOCN ;Initial Catalog=EyeCareCenter ; Trusted_Connection=True ";
    private SqlConnection connection = new SqlConnection();

    public void OpenConnection()
    {
        try
        {

            connection.ConnectionString = connectionstring ;
            connection.Open();
          //  MessageBox.Show (" Connection successfull ... ");

        }

        catch ( Exception a)
        {
            MessageBox.Show(a.Message + " ");

        }
    }
    public void CloseConnection()
    {
        connection.Close();

    }
    public SqlConnection GetConnection()
    {
        return connection;

    }

}

}

至少,您的连接字符串正在尝试连接到VM内部的数据库,而不是主机上的数据库:

私有字符串连接字符串=@“数据源=127.0.0.1,1433;网络库=DBMSSOCN;初始目录=EyeCareCenter;可信连接=True”


应将IP更改为主机的IP以连接到它。并确保您的虚拟机已配置为联网,并且联网配置允许连接到主机。

什么是“无法工作”?特别是不起作用的。请不要在评论中回复-更新您的问题。您的虚拟机是否配置为允许联网?如果是这样,您是否能够从VM访问主机?也就是说,这可能是虚拟机配置问题,而不是代码问题。您需要确定您的“外部”计算机的IP在虚拟机的“内部”是什么。这可能就是您需要在DSN中使用的IP>