Last post Oct 22, 2015 04:45 PM by Maurice Osborn
Oct 07, 2015 08:16 PM|Maurice Osborn|LINK
Errors occur everywhere there is an attempt to access a database table, such as with “TextTable texttable = db.TextTables.SingleOrDefault(p => p.TexID == TextID);” which state: Error 16 'System.Data.Linq.Table<TransLangTable>'
does not contain a definition for 'SingleOrDefault'. Errors also occur whenever there is an attempt to access the database directly such as with “SqlConnection conn = null;” which state: Error 52 The type or
namespace name 'SqlConnection' could not be found.
Obviously, I included a “using System.Data.SqlClient;” statement in the code section along with many others. There is also a statement of: “<add name="ENCdbConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ENCdb.mdf;Integrated
Security=True;User Instance=True" providerName="System.Data.SqlClient"/> within the connectionStrings portion of the web.config file. In addition, there is, “string ENCconn = ConfigurationManager.ConnectionStrings["ENCdbConnectionString"].ToString();” at
the start of the script portion of the code.
I believe that the problem is due to the fact that I only copied the database and DataClasses from another website into my current website instead of creating them directly. For some reason, the Debug function cannot relate to any of my code that relates
to the database. I even attempted to copy the code into a new web page file within the other website where all other web pages work fine with the database. However, I obtained the exact same results with this file when I attempted to run it. What am I doing
wrong? Please help.
Oct 07, 2015 11:28 PM|Candice Zhou|LINK
Based on your code, you modified like below:
In Web.config file:
<add name="ENCdbConnectionString" connectionString="Data Source==.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\ENCdb.mdf;Initial Catalog=ENCdb;Integrated Security=True" providerName="System.Data.SqlClient" />
On .aspx.cs page:
string ENCconn = ConfigurationManager.ConnectionStrings["ENCdbConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(ENCconn);
Oct 08, 2015 03:20 PM|Maurice Osborn|LINK
Thank you for your response. The replacement of your new code in the web.config file appears to work just fine, but the replacement of your code in my aspx.cs page is causing an error that states: Error 17 The type or namespace name 'SqlConnection' could
not be found. Strangely, when I tried to correct this error by removing the portion: “SqlConnection con = new SqlConnection(ENCconn);” it caused the errors to reappear everywhere that there was an attempt to access a database table. This is just what occurred
previously without your code. Obviously, this appears to be the key to my problem. Please help.
Oct 09, 2015 08:11 AM|Candice Zhou|LINK
Hi Maurice Osborn,
when I tried to correct this error by removing the portion: “SqlConnection con = new SqlConnection(ENCconn);” it caused the errors to reappear everywhere
I think you could use Ctrl+F, and then choose Entire Solution to search SqlConnection. You should make sure all the classes which have SqlConnection have added reference: “using System.Data.SqlClient;” .
If all the classes have added reference, you should check out your Visual Studio version and environment.
Oct 09, 2015 01:39 PM|Maurice Osborn|LINK
I performed the search in the Entire Solution for SqlConnection, which found everywhere that this was used within my code for the web page. I’m not sure what you mean by “You should make sure all the classes which have SqlConnection have added reference:
“using System.Data.SqlClient;”. The “using System.Data.SqlClient;” statement is certainly included at the top of every web page code module. My Visual Studio version works fine with all other websites that interface with an SQL database. Am I missing anything
Oct 10, 2015 11:29 AM|Candice Zhou|LINK
My Visual Studio version works fine with all other websites that interface with an SQL database.
Based on your description, it is hard to say the root cause of your issue, but I suggest you creating new project and restoring your original project. If your environment is normal, the reference issue should not be existing.
Oct 22, 2015 04:45 PM|Maurice Osborn|LINK
To all of those who have provided so much help to me,
I apologize. I have just discovered that I have been specifying “using System.Data; using System.Data.SqlClient; and using System.Linq; instead of including the following import statements to enable a connection with my database.
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
All is working well now. I am sorry for troubling you with my problem when the solution was so simple. But, I appreciate your efforts.