我正在尝试使用ASP.NET MVC 3连接到我的SQL Server 2008数据库.这是我的连接字符串:
<connectionStrings>
<add name="AppConnectionString"
connectionString="Data Source=(local);Initial Catalog=DatabaseName;User Id=UserName;Password=PassWord;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
什么是错的?
当我尝试在DbContext中查询某些内容时,我得到以下异常:
$ exception {"提供程序未返回ProviderManifestToken字符串."} System.Exception {System.Data.ProviderIncompatibleException}
InnerException {"与SQL Server建立连接时发生与网络相关或特定于实例的错误.未找到服务器或无法访问服务器.验证实例名称是否正确以及SQL Server是否配置为允许远程连接. provider:SQL网络接口,错误:26 - 找到指定的服务器/实例时出错)"} System.Exception {System.Data.SqlClient.SqlException}
有人可以帮帮我吗?
谢谢
我正在尝试在Azure(9月工具包)中设置Staging and Live环境,我想要一个单独的Staging and Live数据库 - 使用不同的连接字符串.显然,我可以在Visual Studio中使用web.config转换来实现这一点,但是有一种方法可以在VIP交换期间自动更改连接字符串 - 以便登台站点指向暂存数据,将实时站点指向实时数据?我宁愿不必两次部署.
我尝试使用我的ASP.NET MVC 2项目运行ELMAH但是有一些问题可以让它与我的SQL Server 2008 R2数据库一起使用.
这就是我所做的.
在我的数据库中运行dbscript,不小心我运行了两次,但在这种情况下似乎并不重要.
将以下部分添加到我的web.config(下configSection):
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="MyEntities" />
</elmah>
Run Code Online (Sandbox Code Playgroud)这就是我的Entity Framework连接字符串的样子:
<add name="MyEntities"
connectionString="metadata=res://*/Models.Model.MyEntities.csdl|res://*/Models.Model.MyEntities.ssdl|res://*/Models.Model.MyEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=000.000.000.000;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=[username];Password=[password];MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)访问admin/elmah /页面时,我收到以下异常:
不支持关键字:'元数据'.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.ArgumentException:不支持关键字:'metadata'.
来源错误:
在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.
堆栈跟踪:
[ArgumentException:不支持关键字:'metadata'.]
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable,String connectionString,Boolean buildChain,Hashtable synonyms definitions,Boolean firstKey)+5110868
System.Data.Common.DbConnectionOptions..ctor( String connectionString,Hashtable synonyms,Boolean useOdbcRules)+98
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)+64
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString,DbConnectionOptions previous)+24
System.Data.ProviderBase .DbConnectionFactory.GetConnectionPoolGroup(String connectionString,DbConnectionPoolGroupOptions poolOptions,DbConnectionOptions&userConnectionOptions)+150
System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value)+59
我究竟做错了什么?
asp.net-mvc connection-string elmah web-config sql-server-2008-r2
我正在使用Entity Framework Code First 4.3 + Azure并且无法连接到数据库.我得到的错误如下(在第一个查询上):
Keyword not supported: 'server'.
Run Code Online (Sandbox Code Playgroud)
我在Web.config中设置了以下连接
<configSections>
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<connectionStrings>
<add name="TestDBContext"
connectionString="Server=tcp:[SUBSCR].database.windows.net,1433;Database=[MyDB];User ID=[user];Password=[pass];Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True"
providerName="System.Data.EntityClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我的DbContext实现类使用连接字符串的名称:
public class MyContext : DbContext, IMyContext
{
public MyContext()
: base("TestDBContext")
{
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
}
Run Code Online (Sandbox Code Playgroud)
你能说出发生了什么吗?
entity-framework connection-string azure code-first ef-code-first
我使用 .NET 的 OdbcConnectionStringBuilder 来更新从配置文件读取的连接字符串,这使其键小写,如 MS 所记录(“数据源”->“数据源”)。
连接字符串用于访问 MS SQL Server(2008,如果有区别的话)。
它在我的机器(Windows 7 32 位)上运行良好,根据MS 的文档,它应该可以运行:
关键字不区分大小写
然而,在其他几台机器上(至少有一些是64位的),无法使用这个小写字母打开与DB的连接。只有在手动将关键字更改为其原始大小写(每个单词的字母大写)后,数据库连接才会打开。
连接字符串中的关键字(全部修改为小写):
Data SourceInitial CatalogIntegrated Security这个对另一个问题的回答指出:
不要忘记首先清除连接字符串:
<connectionStrings>
<clear />
<add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
... 有趣的。那有什么作用?
我正在尝试使用以下代码片段打开与 MySql 数据库的连接:
string connectionString = "Server=ip_number;Database=database_name;Uid=uid;Password=password";
MySqlConnection connection;
connection = new MySqlConnection(connectionString);
connection.Open();
Run Code Online (Sandbox Code Playgroud)
这是我得到的例外:

我正在使用最新的 mysql 连接器(从此处下载)。我缺少什么?
提前致谢,
我正在尝试通过在 Visual Studio 2013 中创建的 ASP.NET WebForms 网站从 MS Azure 上托管的 SQL Server 数据库中读取数据。
我已经在 Web.Config 中存储了连接字符串,并在我的代码隐藏中引用了它。
但是,当我尝试在本地运行 Default.aspx 时,会显示此错误。
这是我的 Web.Config:
<connectionStrings>
<add name="FYPConnectionString1"
connectionString="Data Source=damo.database.windows.net??;Initial Catalog=Ballinora_db;
Persist Security Info=True; User ID={Username};Password={Password};" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
我从连接字符串中删除了“MultipleActiveResultsSets=False”以查看错误是否停止,但现在显示“加密”错误。
因此错误出现在连接字符串的密码部分之后的下一项。密码是否与问题有关?
此外,此用户名和密码是必需的,它们是 Azure 门户中显示的服务器管理员登录详细信息吗?
这里也是代码隐藏:
private void bindRepeater()
{
string constr = ConfigurationManager.ConnectionStrings["FYPConnectionString1"].ConnectionString;
//-- assuming Azure connection string stored in ConnectionString config in Web.Config as YourConnString
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Name FROM Users", …Run Code Online (Sandbox Code Playgroud) 我有 ASP.NET MVC 应用程序,我正在尝试连接到在 Azure 上迁移的 Azure SQL 数据库。我需要在 web.config 中设置我的连接字符串,但我不知道在哪里查找用户 ID 和密码。我在 Azure 中的 SQL Server 概述中发现了这样的模式:
Server=tcp...;User ID={your_username};Password={your_password}...;
Run Code Online (Sandbox Code Playgroud)
我发现有 username@server.com 并阅读了有关设置 Active Directory 管理员的信息。不幸的是,我是一名学生,并且拥有面向学生的 Azure,但我无法设置此类管理员。
我假设登录名将是数据库“mydb”的名称,密码是它的密码。不幸的是,它不起作用,当我登录到我的应用程序时,它会出现以下错误:
System.Data.SqlClient.SqlException: Login failed for user 'mydb'.
Run Code Online (Sandbox Code Playgroud)
我在论坛上没有找到答案,但如果有请告诉我。
提前感谢大家的帮助:)
我是 Asp.Net Core 和 EF 的新手。我正在从数据库端开发一个简单的 CRUD,使用该Secrets.json文件隐藏我的连接字符串凭据。
但我不知道如何使用 AddDbContext() 引用该文件。
到目前为止我的代码:
public class Startup
{
public Startup(IConfigurationRoot configuration)
{
Configuration = configuration;
}
public IConfigurationRoot Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<POTS.myDBContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("myConxStr")));
services.AddControllers();
}
Run Code Online (Sandbox Code Playgroud)
当代码运行时,我收到此AddDbContext<>错误
System.ArgumentNullException HResult=0x80004003 Message=值不能为空。(参数'connectionString')
来源= Microsoft.EntityFrameworkCore.SqlServer StackTrace:等等
我认为这是因为代码正在文件中查找参数appsettings.json,而我不希望连接字符串在其中。
我缺少什么?
entity-framework connection-string asp.net-core secretsmanager
azure ×4
asp.net ×3
.net ×2
asp.net-mvc ×2
c# ×2
asp.net-core ×1
code-first ×1
elmah ×1
keyword ×1
mysql ×1
sql ×1
sql-server ×1
web-config ×1