热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法在C#中访问远程数据库-unabletoaccessremotedatabaseinC#

ihavechangedtheconnectionstringtopointtoadatabaseintheremoteserver.ButwhenIexecute

i have changed the connection string to point to a database in the remote server. But when I execute the project the program still points to the local db.

我已将连接字符串更改为指向远程服务器中的数据库。但是当我执行项目时,程序仍然指向本地数据库。



  




 





 

Comments are the different connection strings i have treid so far. i never had a connections string when I was using the LocalDB.

注释是我到目前为止所遇到的不同连接字符串。我在使用LocalDB时从未有过连接字符串。

Constructor for Connection

连接的构造函数

public class TedalsContext : DbContext
{
    public TedalsContext()
        : base("TedalsContext")
    {
        //Database.SetInitializer(null);
    }
}

i am using SQL Server Express as my database. I have also tried changing the name of the parameter for base in constructor as the name of the Database. But it did not change anything.

我使用SQL Server Express作为我的数据库。我也尝试在构造函数中更改base的参数名称作为数据库的名称。但它没有改变任何东西。

I have already tried if I have access to the database through SSMS. I am able to create tables but I am unable to rename the database as such(I do not have access rights to rename the database TeDalSdev).

如果我可以通过SSMS访问数据库,我已经尝试过了。我能够创建表,但我无法重命名数据库(我没有重命名数据库TeDalSdev的访问权限)。

Are there any other work around i could try? Should the name of the remote database and the local database should be the same to avoid changing a lot of code?

我还有其他可以尝试的工作吗?远程数据库和本地数据库的名称应该相同,以避免更改大量代码吗?

UPDATE

UPDATE

Controller

调节器

public class LsystemFamiliesController : Controller
{
    private TedalsContext db = new TedalsContext();
    //Code goes here
}

2 个解决方案

#1


4  

I've added a connection string from a web config file of one of my projects and all the fields that (should) be checked. This is within the tags. You need to make it your default connection and you can only have one connection string as the default connection.

我已经从我的一个项目的Web配置文件和(应该)检查的所有字段添加了一个连接字符串。这在 标记内。您需要将其设置为默认连接,并且只能将一个连接字符串作为默认连接。


Where you have your DB Context:

您拥有数据库上下文的位置:

public TedalsContext()
    : base("DefaultConnection")

Switch everything to DefaultConnection, until you get it working, then you can focus on changing names. Comment out your local db connection strings. Even remove it from the project if you need to (and save it elsewhere), while you are testing this.

将所有内容切换到DefaultConnection,直到它正常工作,然后您可以专注于更改名称。注释掉本地数据库连接字符串。如果您需要(甚至将其保存在其他地方),甚至在测试时将它从项目中删除。

I've also added a screen shot of the my folder directory, to show which web config folder I am modifying. See it's highlighted in blue.

我还添加了我的文件夹目录的屏幕截图,以显示我正在修改的Web配置文件夹。看到它以蓝色突出显示。

enter image description here

Also this screen shot shows you where to navigate to test your connection string within VS.

此屏幕截图还显示了在VS中测试连接字符串的导航位置。

enter image description here

I suggest you look here:

我建议你看看这里:

How to: Access SQL Server Using Windows Integrated Security

如何:使用Windows集成安全性访问SQL Server

What will be the connectionstring for mssql windows authentication

mssql windows身份验证的连接字符串是什么

and this:

和这个:

Connection string using Windows Authentication

连接字符串使用Windows身份验证

As I suggested in the discussion. I recommend also contacting web hosting provider, as I have had this problem where it will not connect and it's been a problem at the hosting end.

正如我在讨论中所建议的那样。我建议也联系网络托管服务提供商,因为我有这个问题,它将无法连接,这是在托管端的问题。

If you need more help, shout out.

如果您需要更多帮助,请大声喊出来。

#2


0  

Under your TedalsContext constructor, use : base(connectionStringName).

在您的TedalsContext构造函数下,使用:base(connectionStringName)。

Otherwise, the context will treat it as code first and create a TedalContext inside your SQLExpress Local DB.

否则,上下文将首先将其视为代码,并在SQLExpress Local DB中创建TedalContext。

public class TedalsContext : DbContext
{
    public TedalsContext()
        : base("TEDALS_Ver01.DAL.TedalsContext")
    {
        //Database.SetInitializer(null);
    }
}

推荐阅读
  • Windows服务与数据库交互问题解析
    本文探讨了在Windows 10(64位)环境下开发的Windows服务,旨在定期向本地MS SQL Server (v.11)插入记录。尽管服务已成功安装并运行,但记录并未正确插入。我们将详细分析可能的原因及解决方案。 ... [详细]
  • 本文详细探讨了JDBC(Java数据库连接)的内部机制,重点分析其作为服务提供者接口(SPI)框架的应用。通过类图和代码示例,展示了JDBC如何注册驱动程序、建立数据库连接以及执行SQL查询的过程。 ... [详细]
  • 本文探讨了MariaDB在当前数据库市场中的地位和挑战,分析其可能面临的困境,并提出了对未来发展的几点看法。 ... [详细]
  • 深入理解 SQL 视图、存储过程与事务
    本文详细介绍了SQL中的视图、存储过程和事务的概念及应用。视图为用户提供了一种灵活的数据查询方式,存储过程则封装了复杂的SQL逻辑,而事务确保了数据库操作的完整性和一致性。 ... [详细]
  • 本文深入探讨 MyBatis 中动态 SQL 的使用方法,包括 if/where、trim 自定义字符串截取规则、choose 分支选择、封装查询和修改条件的 where/set 标签、批量处理的 foreach 标签以及内置参数和 bind 的用法。 ... [详细]
  • 通过Web界面管理Linux日志的解决方案
    本指南介绍了一种利用rsyslog、MariaDB和LogAnalyzer搭建集中式日志管理平台的方法,使用户可以通过Web界面查看和分析Linux系统的日志记录。此方案不仅适用于服务器环境,还提供了详细的步骤来确保系统的稳定性和安全性。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 深入解析Spring Cloud Ribbon负载均衡机制
    本文详细介绍了Spring Cloud中的Ribbon组件如何实现服务调用的负载均衡。通过分析其工作原理、源码结构及配置方式,帮助读者理解Ribbon在分布式系统中的重要作用。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • 本文详细介绍了如何通过多种编程语言(如PHP、JSP)实现网站与MySQL数据库的连接,包括创建数据库、表的基本操作,以及数据的读取和写入方法。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 本文详细介绍了 Apache Jena 库中的 Txn.executeWrite 方法,通过多个实际代码示例展示了其在不同场景下的应用,帮助开发者更好地理解和使用该方法。 ... [详细]
  • MySQL 数据库迁移指南:从本地到远程及磁盘间迁移
    本文详细介绍了如何在不同场景下进行 MySQL 数据库的迁移,包括从一个硬盘迁移到另一个硬盘、从一台计算机迁移到另一台计算机,以及解决迁移过程中可能遇到的问题。 ... [详细]
  • 图数据库中的知识表示与推理机制
    本文探讨了图数据库及其技术生态系统在知识表示和推理问题上的应用。通过理解图数据结构,尤其是属性图的特性,可以为复杂的数据关系提供高效且优雅的解决方案。我们将详细介绍属性图的基本概念、对象建模、概念建模以及自动推理的过程,并结合实际代码示例进行说明。 ... [详细]
  • PostgreSQL 10 离线安装指南
    本文详细介绍了如何在无法联网的服务器上进行 PostgreSQL 10 的离线安装,并涵盖了从下载安装包到配置远程访问的完整步骤。 ... [详细]
author-avatar
Jin_木_木_176
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有