如何将 SQL Server 连接到 .NET 项目

huangapple go评论71阅读模式
英文:

How to connect SQL Server back to .NET project

问题

为了提供一些背景信息,我被指派成为一个使用.NET框架开发的网站的维护人员,我们失去了与之前的开发人员的联系。话虽如此,我对.NET世界有点陌生,需要一些时间来适应,还有一件事情需要弄清楚,就是如何将SQL Server数据库重新连接到项目中(它托管在公司服务器上),而且我还不知道他们在使用什么类型的SQL Server。

我尝试在web.config文件中找到一些线索,但没有得出任何结论:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameters>
            <parameter value="mssqllocaldb" />
        </parameters>
    </defaultConnectionFactory>
    <providers>
        <provider invariantName="System.Data.SqlClient" 
                  type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
</entityFramework>

此外,在web.config中,我还有以下内容(出于安全原因删除了信息):

<connectionStrings>
    <add name="" connectionString="data source=MSI;initial catalog=MelkiDBbranch1;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>

还有一个与SQL相关的非常长的Entity Framework文件,我将很快访问本地服务器,但我需要大致了解一下,在我的计算机上建立连接时应该查找什么。

英文:

To give a bit of context, I was assigned to be a maintainer for a website developed with .NET framework, we lost contact with previous developer. That said, I'm a bit new to the .NET world and will need a bit of time to adapt, one thing is left to figure out how to connect the SQL Server database back to the project (it is hosted locally on the company server), and I still don't know what SQL Server type they are using.

I tried locating some clues in the web.config file but didn't come to any conclusion:

&lt;entityFramework&gt;
    &lt;defaultConnectionFactory type=&quot;System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework&quot;&gt;
        &lt;parameters&gt;
            &lt;parameter value=&quot;mssqllocaldb&quot; /&gt;
        &lt;/parameters&gt;
    &lt;/defaultConnectionFactory&gt;
    &lt;providers&gt;
        &lt;provider invariantName=&quot;System.Data.SqlClient&quot; 
                  type=&quot;System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer&quot; /&gt;
    &lt;/providers&gt;
&lt;/entityFramework&gt;

Also in the web.config i have the following (removed information for security reasons):

  &lt;connectionStrings&gt;
    &lt;add name=&quot;&quot; connectionString=&quot;data source=MSI;initial catalog=MelkiDBbranch1;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework&quot; providerName=&quot;System.Data.SqlClient&quot; /&gt;
  &lt;/connectionStrings&gt;

Along with a really long Entity Framework file which is SQL related, I will access the local server soon but I need to have a general idea on what I should look for in order to establish the connection on my PC

答案1

得分: 1

我们有这个连接字符串:

data source=MSI;initial catalog=MelkiDBbranch1;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework

这个连接字符串告诉我们服务器名称是MSI,而该服务器上的数据库名称是MelkiDBbranch1(因为一个服务器可以托管_多个_数据库)。我预计用户ID和密码已经被编辑,您可以在实际字符串中看到实际值。

要连接到这个服务器,您需要确保MSI名称在您的网络上解析(可能有一个默认的DNS后缀)。如果您使用SQL Server Management Studio,然后可以使用连接字符串中的登录/密码,选择SQL Server身份验证,并使用MSI名称连接到数据库引擎。

如果您展开“选项”部分,应该也有一个选择数据库的地方,但这是可选的。

最后,根据网络和防火墙配置,您可能可以在自己的计算机上安装Management Studio,而无需首先登录到服务器。

英文:

We have this connection string:

data source=MSI;initial catalog=MelkiDBbranch1;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework

This connection string tells us the server name is MSI, and the database name on that server is MelkiDBbranch1 (since one server can host many databases). I expect the user id and password are redacted, and you can see actual values in the real string.

To connect to this server you need to make sure the MSI name resolves on your network (there's probably a default dns suffix). If you're using SQL Server Management Studio, you can then connect to a database engine using the MSI name for the server, with SQL Server Authentication selected and using the login/password from the connection string.

If you expand the "Options" section there should also be a place to choose the database, but this is optional.

如何将 SQL Server 连接到 .NET 项目

Finally, depending on the network and firewall configurations, you can probably do this with Management Studio installed on your own computer, without needing to first login to the server.

huangapple
  • 本文由 发表于 2023年7月31日 23:18:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804996.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定