ConfigurationManager not declared - Have dll - vb.net

Quick background: I have a VB.NET application in which I was previously using ConfigurationSettings.AppSettings to read from app.config, and got an error message to change it to System.Configuration.ConfigurationManager.AppSettings (as the first way is now obsolete)
I did so, and I even have a reference to System.Configuration.dll AND the Imports statement at the top, but I am getting a "Name ConfigurationManager not declared" error message. Any suggestions?
CODE:
It's pretty straightforward - I'm just checking if something exists, and if it does, I read from it:
If Not Exists(ConfigurationManager.AppSettings.Get(rep & "Email")) Then
Return False
End If
message = ReadAllText(ConfigurationManager.AppSettings.Get(rep & "Email"))

The project template doesn't have the reference you need. Project + Add Reference, select "System.Configuration".
For more insight, click the "Show All Files" icon at the top of the Solution Explorer window and open the References node.

Another issue that causes this is the reference being the wrong case.
System.configuration was in the .vbproj, instead of System.Configuration.
For me, compiling with the above mistake worked on Windows but not on Linux, but fixing it to the latter made it work on both.

If you are using visual studio 2015 and Visual Basic language. Go to Project + Add Reference > Select Assemblies > Framework. Search for System.configuration. Add the DLL file. After it. On your form, add this in the first line without quotations "Imports System.Configuration" go to your connection string declaration then put this value without quotation "ConfigurationManager.ConnectionStrings("'string configuration name'").ConnectionString" like this.
Public constr As String = ConfigurationManager.ConnectionStrings("string configuration name").ConnectionString
This one works for me. Just now. Hope this one helps others. ^_^

Related

Webforms Error shows TWO projects although solution shows ONE project

In a VS-2019 webforms solution I get this error that shows TWO projects although the solution only has ONE project.
Severity: Error
Code Description : BC30456 'prpPageCaption' is not a member of 'MasterPage'.
Project: 7_SessionExpired.aspx, repo_TripManagement
File: C:\Users...\SessionExpired.aspx.vb
Line: 100
Suppression State: Active
It appears that the error shows TWO projects and I did not create a project named 7_SessionExpired.aspx
The vb-page "SessionExpired.aspx and .vb" was copied from a similar project in VS-2017. This is confusing to me and I don't have any way to know what this error is saying.
Here is the LINE=100 from the source VB file:
100| | Master.prpPageCaption = "Session has Expired"
Here is the property in the master-page:
Public Property prpPageCaption() As String
Get
Return Me.lblCaption.Text
End Get
Set(ByVal p_sCaption As String)
Me.lblCaption.Text = p_sCaption
Me.updpanelPageCaption.Update()
End Set
End Property
The vb-page "SessionExpired.aspx and .vb" was copied from a similar project in VS-2017. This is confusing to me and I don't have any way to know what this error is saying. I need your help. Thanks...John
Think the IDE/VS-2019 is confused and I cut ALL of the files for SessionExpired.aspx (.vb) and pasted them in a my-documents-folder.
I then added a webform-page with Master-page (WebForm1.aspx) into the project.
I then added the ASPX objects as UI for the page. I performed a "View Code" option and the / VB-code structure is shown. I only added "Option Explicit ON". Saved both modified files and closed the SOLUTION.
I then re-opened the solution and the code compiled -- even though the full VB-functionality was not coded.
From the 'Solution Explorer' I then renamed the WebForm1.aspx to "SessionExpired" and compiled again -- all ok.
Finally I added the VB-code from the saved-off original SessionExpired.vb code.
All of the errors shown above were cleared and things are working.
IMHO, bringing in an older webform brings with it the old-style of 'designer' and by starting with a VS-2019 webform-page conforms to the VS-2019 designer pattern.
I apologize to those that viewed this question.
Thanks. John.

Visual Studio Code change my html code by itself and break all

Someone know the solution for this:
I have a simple Angular code inside Visual Studio Code and every time i save a file a fragment is changed by itself.
It: <app-mytag [myVarHere]="myVarHere"></app-mytag>
becomes it: <app-mytag></app-mytag>
by the simple act of save the file.
Im using nano editor outside to solve it.
Its my plugin list:
1tontech.angular-material
4tron.angular-material-snippets
Angular.ng-template
AngularDoc.angulardoc-vscode
EditorConfig.EditorConfig
GregorBiswanger.json2ts
HookyQR.beautify
MarinhoBrandao.Angular2Tests
NG-42.ng-fortytwo-vscode-extension
SimonTest.simontest
UVBrain.Angular2
abusaidm.html-snippets
anweber.vscode-tidyhtml
christian-kohler.npm-intellisense
christian-kohler.path-intellisense
dbaeumer.vscode-eslint
eg2.tslint
eg2.vscode-npm-script
esbenp.prettier-vscode
felixfbecker.php-debug
felixfbecker.php-intellisense
felixfbecker.php-pack
formulahendry.auto-close-tag
formulahendry.auto-rename-tag
jasonnutter.search-node-modules
johnpapa.Angular2
loiane.angular-extension-pack
ms-vscode.autorest
ms-vscode.cpptools
ms-vscode.typescript-javascript-grammar
msjsdiag.debugger-for-chrome
pkosta2006.rxjs-snippets
robertohuertasm.vscode-icons
steoates.autoimport
vuhrmeister.vscode-meteor
waderyan.nodejs-extension-pack
xabikos.JavaScriptSnippets
I think the culprit is anweber.vscode-tidyhtml plugin you are using. The reason why you lose the angular annotations is that, you have enabled tidyHtml.formatOnSave to true
You can disable the plugin or try removing tidyHtml.formatOnSave from your user settings by going in to:
Ctrl + F1 and type user settings
PS - I tried to recreate your problem and here's what happens:

How do you see what SQL IronSpeed sends to the database?

I'm using IronSpeed Designer 12.2 and trying to write custom SQL in a WhereClause override. The custom SQL I wrote and submitted in the WhereClause is throwing an SQL exception, but I can't see the SQL IronSpeed is sending to the database. Without the SQL, I cannot troubleshoot.
I can't find where the SQL is submitted to the database, such as by an ExecuteReader method call.
I'm using a statement like this:
if (MiscUtils.IsValueSelected(this.MyFilter)) {
String sql = "(EXISTS (SELECT TOP 1 CompanyId FROM Collateral as c WHERE CODE = '{0}' AND c.CompanyId = Company.CompanyId))";
wc.iAND(String.Format(sql, this.MyFilter.SelectedValue));
}
I know my WhereClause SQL is correct when used outside of IronSpeed because I copy-pasted it from a query working directly in MSSQL. However I can't see how IronSpeed combines it with its internally-generated SQL after it becomes a WhereClause.
I'm hoping someone has experience with this issue and can point me in the right direction. Thanks for the help!
If you look for answer long enough, you can find it yourself. Here's how I found you can examine the SQL sent to the database:
Go to C:\Program Files\Iron Speed\Designer v12.2.0.
Copy the BaseClasses folder to the root of my IronSpeed solution folder.
Add the existing BaseClasses project to the IronSpeed solution.
Delete the existing references to baseclasses.dll from the projects in the IronSpeed solution (I'm using a web app rather than web site project).
Add references to the BaseClasses project now included in the solution.
Open the file MicrosoftDynamicSQLAdapter.vb.
In method GetRecordValuesEx(...), go to line 1514 statement "reader = SqlTransaction.ExecuteReader(myCommand, cmdBehavior)" and set a breakpoint on this line.
Run the project. When the breakpoint is hit, examine the command of myCommand object.

DB Query no longer recognizes SQL parameters in existing application when debugging in VS2010

I just started working with an application that I inherited from someone else and I'm having some issues. The application is written in C# and runs in VS2010 against the 3.5 framework. I can't run the application on my machine to debug because it will not recognize the way they referenced their parameters when writing their DB queries.
For instance wherever they have a SQL or DB2 query it is written like this:
using (SqlCommand command = new SqlCommand(
"SELECT Field1 FROM Table1 WHERE FieldID=#FieldID", SQLconnection))
{
command.Parameters.AddWithValue("FieldID", 10000);
SqlDataReader reader = command.ExecuteReader();
...
If you will notice the "parameters.AddWithValue("FieldID", 10000);" statement does not include the "#" symbol from the original command text. When I run it on my machine I get an error message stating that the parameter "FieldID" could not be found.
I change this line:
command.Parameters.AddWithValue("FieldID", 10000);
To this:
command.Parameters.AddWithValue("#FieldID", 10000);
And all is well... until it hits the next SQL call and bombs out with the same error. Obviously this must be a setting within visual studio, but I can't find anything about it on the internet. Half the examples for SQL parameter addition are written including the "#" and the other half do not include it. Most likely I just don't know what to search for.
Last choice is to change every query over to use the "#" at the front of the parameter name, but this is the transportation and operations application used to manage the corporation's shipments and literally has thousands of parameters. Hard to explain the ROI on your project when the answer to the director's question "How's progress?" happens to be "I've been hard at it for a week and I've almost started."
Has anyone run into this problem, or do you know how to turn this setting off so it can resolve the parameter names without the "#"?
Success! System.Data is automatically imported whenever you create a .NET solution. I removed this reference and added it back to make sure that I had the latest version of this library and that fixed the issue. I must have had an old version of this library that was originally pulled in... only thing I can figure.
Its handled by the .NET Framework data providers not Visual Studio.
It depends on the data source. Look here:Working with Parameter Placeholders
You can try working with System.Data.Odbc provider and using the question mark (?) place holder. In thios case dont forget to add the parameters in the same order they are in the query.

Executable directory where application is running from?

I need to get the path (not the executable) where my application is running from:
System.AppDomain.CurrentDomain.BaseDirectory()
When I run the above statement with & "/images/image.jpg" on my local machine it works fine but when I install the application on another machine it says it cannot find the file and there is a lot of extra path information some.
I just need the directory of where the app is running. I am coding in VB.NET with Visual Studio 2008.
Thanks!
This is the first post on google so I thought I'd post different ways that are available and how they compare. Unfortunately I can't figure out how to create a table here, so it's an image. The code for each is below the image using fully qualified names.
My.Application.Info.DirectoryPath
Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath
AppDomain.CurrentDomain.BaseDirectory
System.Reflection.Assembly.GetExecutingAssembly.Location
System.Reflection.Assembly.GetExecutingAssembly.CodeBase
New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase)
Path.GetDirectoryName(Uri.UnescapeDataString((New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase).Path)))
Uri.UnescapeDataString((New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase).Path))
---
Edit October 18, 2021:
Sigh... None of the above work if using net5.0 or net6.0 and publishing app as single-file bundle. Best I got now is:
// This will give you the directory but not the assembly
string basedir = AppContext.BaseDirectory;
// Before you package the app as a single file bundle, you will get the dll.
// But after you publish it, you'll get the exe.
string pathToExecutable = Environment.GetCommandLineArgs()[0].Replace(".dll", ".exe");
Dim strPath As String = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
Taken from HOW TO: Determine the Executing Application's Path (MSDN)
I needed to know this and came here, before I remembered the Environment class.
In case anyone else had this issue, just use this: Environment.CurrentDirectory.
Example:
Dim dataDirectory As String = String.Format("{0}\Data\", Environment.CurrentDirectory)
When run from Visual Studio in debug mode yeilds:
C:\Development\solution folder\application folder\bin\debug
This is the exact behaviour I needed, and its simple and straightforward enough.
Dim P As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
P = New Uri(P).LocalPath
You could use the static StartupPath property of the Application class.
You can write the following:
Path.Combine(Path.GetParentDirectory(GetType(MyClass).Assembly.Location), "Images\image.jpg")