连接字符串无效或错误定位服务器/实例

编程入门 行业动态 更新时间:2024-10-23 14:32:40
本文介绍了连接字符串无效或错误定位服务器/实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我重新安装了PC,现在我的SQL连接字符串或SQL Server 2012 Enterprise出现了问题错误提示:

I reinstaled my PC and now I have problems with my SQL connection string or with SQL Server 2012 Enterprise Error I get:

"... (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)" or "... (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

在SQL Server Management Studio服务器实例中,如下所示:

In SQL Server Management Studio server instance looks like this:

TOM-PC (SQL Server 11.0.3128 - Tom-PC\Tom)

以及ASP.NET XML配置中的My SQL连接字符串.文件:

And My SQL connection string in ASP.NET XML config. file:

<add name="ApplicationServices" connectionString="Data Source=.\TOM-PC;Database=D:\Programming\InvoiceManager\invocemanagerSQL.mdf;" providerName="System.Data.SqlClient" />

尝试所有操作,在防火墙中添加了端口1434或1433,这两个端口均经过测试,无法正常工作,"SQL Server Browser" 服务正在运行,已启用TCP/IP,允许远程连接到该服务器,甚至尝试了4不同的连接字符串,无济于事.在它像魅力一样起作用之前,还没有完全发挥作用,但是起作用了.为什么不充分?因为我无法同时在两个工作室"VS2010" 和"SQL Management studio" 的本地计算机上工作,所以如果我需要手动更改数据库中的某些内容,我需要停止或重新启动SQL Server进程和服务,然后进入数据库并读取表.现在,什么都没有起作用!我做错了什么?问题似乎在哪里?为什么SQL Server及其连接字符串总是有问题?

Tried everything, in firewall added port 1434 or 1433 tested both, not working, "SQL Server Browser" Service is running, TCP/IP Enabled, Allow remote connections to this server, even tried 4 different connection strings, nothing worked. Before it worked like a charm, not fully but worked. Why not fully? Because I couldn't work on my local machine with both studios "VS2010" and "SQL Management studio" at the same time, if I needed change something in database manually, I needed to stop or restart SQL Server process and service, then I get in database, and read tables. Now, nothing is working! What I do or did wrong? Where seems to be the problem? Why always are problems with SQL servers and it's connectionstrings?

推荐答案

在Management Studio中看到的内容如下:

What you are seeing in Management Studio is as follows:

Instance Name (SQL Server version - Domain\LoggedInUser)

您使用集成身份验证(即Windows登录帐户)登录,但未在连接字符串中指定该身份.这将尝试使用ASP.Net应用程序的当前登录用户,该应用程序几乎可以肯定不会以Windows帐户的身份运行.它将是本地或网络服务帐户之一,或者是内置的ASP.Net用户.

You are logged in using integrated authentication (i.e. your windows logon account) but not specifying it in the connection string. This will try to use the currently logged on user for the ASP.Net application, which will almost certainly not be running as your windows account. It will either be one of the local or network service accounts or a built-in ASP.Net user.

如果实际上是您想要的,那么您还会使用错误的变量名来附加数据库文件,而不是连接到服务器上的实际数据库.

You're also using the wrong variable name to attach the database file, if this is actually what you want rather than connecting to an actual database on the server.

我建议您做的是在实例上启用SQL Server身份验证,创建一个新用户,并根据需要授予它对数据库的权限.

What I suggest you do is enable SQL Server authentication on your instance, create a new user and give it permissions to the database as required.

然后您将使用以下格式登录:

You would then log in using the following format:

Server=myServerAddress; Database=myDataBase; User Id=myUsername; Password=myPassword;

其中 myServerAddress 是 localhost 或 TOM-PC 的地方;数据库将是出现在Management Studio中的数据库的名称;用户ID 将是您刚刚创建的用户的用户名,而 Password 将是您在创建过程中为其设置的密码.

Where myServerAddress would be localhost or TOM-PC; Database would be the name of the database as it appears in Management Studio; User Id would be the username for the user you just created and Password would be the password you set for them during creation.

如果您确实想附加数据库文件,则您的连接字符串将更改为使用以下格式:

If you do actually want to attach a database file then your connection string changes to use this format:

Server=myServerAddress; AttachDbFilename=C:\Path\To\Database\File.mdf; Database=myDataBase; Trusted_Connection=Yes;

通常,您可以从以下位置获得所需的大多数连接字符串变体: www.connectionstrings/sql-server/

Typically, you can get most connection string variants that you will need from: www.connectionstrings/sql-server/

更多推荐

连接字符串无效或错误定位服务器/实例

本文发布于:2023-10-30 22:47:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544223.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   实例   错误   服务器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!