简体   繁体   English

连接字符串在asp.net网络表单中不起作用

[英]connection string is not working in asp.net webforms

i registered my website on somee.com. 我在somee.com上注册了我的网站。 for that i have uploaded MS SQL database. 为此,我已经上传了MS SQL数据库。 i was wrting this connection string in my code: 我在我的代码中写了这个连接字符串:

connectionString="metadata=res://*/nrcsaEntities.csdl|res://*/nrcsaEntities.ssdl|res://*/nrcsaEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=My-PC;initial catalog=nrcsa;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""

now as i registered somee.com is providing me new connection string that is: 现在,当我注册时,somee.com为我提供了新的连接字符串,即:

workstation id=nrcsadb.mssql.somee.com;packet size=4096;user id=DuaZoya_SQLLogin_1;pwd=abcd;data source=nrcsadb.mssql.somee.com;persist security info=False;initial catalog=nrcsadb

i have changed connectiong string in file web.config by replacing this first connection string with provided connection string by somee.com 我已通过将某些第一个连接字符串替换为somee.com提供的连接字符串来更改了web.config文件中的connectiong字符串

PROBLEM: 问题:

This replacement is generating warning that: 此替换生成警告:

 System.ArgumentException: Keyword not supported: 'user id'.

how to solve this problem? 如何解决这个问题呢?

In the web.config file .... 在web.config文件中。

     <connectionStrings><add name="nameofConnection" connectionString="Data   Source=servername; Initial Catalog=DatabaseName; User ID=UserName; Password=Password;"/>  </connectionStrings>
 <system.web>
<compilation debug="false" targetFramework="4.0" />  </system.web>

you can edit target Framework according to you. 您可以根据自己的需要编辑目标框架。

from : http://dotnet-developers-cafe.blogspot.in/2013/08/create-connection-string-in-aspnet.html 来自: http : //dotnet-developers-cafe.blogspot.in/2013/08/create-connection-string-in-aspnet.html

You're using Entity Framework. 您正在使用实体框架。

Entity Framework has its own connection string which contains a reference to the EF metadata ( metadata=... ) as well as the inner connection string to connect to the actual database. 实体框架有其自己的连接字符串,其中包含对EF元数据的引用( metadata=... ),以及用于连接到实际数据库的内部连接字符串。

You need to insert your actual database connection string inside the EF connection seting, in the provider connection string=... section. 您需要在provider connection string=...部分的EF连接设置中插入实际的数据库连接字符串。
You will also need to add multipleactiveresultsets=True to their connection string; 您还需要在其连接字符串中添加multipleactiveresultsets=True EF needs that setting. EF需要该设置。

Don't replace the whole connection string. 不要替换整个连接字符串。 You will need to remove the Integrated Security = true section and replace it with user=DuaZoya_SQLLogin_1;password=abcd. 您将需要删除Integrated Security = true部分,并将其替换为user = DuaZoya_SQLLogin_1; password = abcd。

Also change the data source to nrcsadb.mssql.somee.com. 还将数据源更改为nrcsadb.mssql.somee.com。

You pretty much just need to replace values in your existing connection string with the values provided. 您几乎只需要用提供的值替换现有连接字符串中的值即可。

As you are using entity famework, then your connection string will look like 当您使用实体框架时,您的连接字符串将如下所示

<connectionStrings>
  <add name="BlogContext" 
        connectionString="metadata=res://*/BloggingModel.csdl|
          res://*/BloggingModel.ssdl| res://*/BloggingModel.msl;
          provider=System.Data.SqlClient 
          provider connection string=&quot;data source=[you somee.com connetion string];&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

what you need to do is simply change the value of data source from the actual connectionstring provided by somee.com 您需要做的就是简单地从somee.com提供的实际连接字符串中更改数据源的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM