database.open No intellisense - asp.net

I'm trying to open a database (using vb) using database.open but there is no Intellisense for this. What do I need to do to open a database? All of the examples I can find show database.open("ConnectionString") but this option isn't available to me.
I'm with with a fresh ASP.NET Razor application (not MVC) and have a web.config reference to a suitable database.

Are you talking about complete ado.net basics? If you are, check this site out: using ado.net with VB.Net and C#
You actually want to create the object for the sql connection before you open the connection:
Dim sqlConn as new SqlConnection("ConnectionString")
sqlConn.Open()
Also, in your web project, you need to add the reference System.Data (this should add System.Data.SqlClient) and this will need to be imported using
Imports System.Data
Imports System.Data.SqlClient
at the top of the page before the class.
Hope this makes sense.

Related

Why Is VS2019 / VB.Net /EF 6 Requiring a Doubling Up on My Imports?

After a multi-year layoff I'm trying to pick back up an application I originally worked on using VSEW 2012 in VB.NET Web Forms against .NET 4.5.1 and EF 5.0. The app recompiled nicely using VS2019 and .NET 4.7.2 until I started trying to "modernize" things, and then all heck broke loose. When I upgraded to EF 6, entity-related "not defined" messages came up by the hundreds. Ah, I see EF5 -> EF6 isn't quite so seamless.
So, to help determine what's going on, I went back and created a new simple Web Forms app and generated an EF 6.2 model from my existing database. All is good - but to use my Entity Container (in the below, AlphaEntities) I have to "double up" the Root Namespace for the project on the Imports statement. Never had to do anything like that before.
I guess I'm just rusty - but what am I missing? I think the answer on this simple app will help me determine what needs to be fixed on my "real" app.
Imports TestWebApp1.TestWebApp1 '<=== Note Root Namespace Doubled Up
Public Class _Default
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Using dbc As New AlphaEntities
testLabel.Text = dbc.Customers.First.Name.ToString
End Using
End Sub
End Class
EDIT: After a night's sleep, I found the part of the project configuration dialog that sets imported namespaces (which wasn't immediately visible, given how my VS windows are arranged) and selected the "doubled up" TestWebApp1.TestWebApp1 namespace. Now the entity container reference correctly compiles without the explicit Imports reference. So I checked my old VSEW 2012 configuration on another laptop and a) it did not require the root namespace to be checked/imported this way, and b) there was not even a "doubled up" option displayed to be imported. So, I'm still unclear why a) I needed to import the namespace in the project config at all (has something changed in this regard since VS2012?), and b) TestWebApp1.TestWebApp1 needs to be imported and not just TestWebApp1.
After some exploration in the VS Object Browser, it turned out that the generated EF part of the entity (partial) classes were for some reason apparently not "merging" into the remainder of the (partial) classes that I was was creating in separate files. Object Browser showed two different classes in the hierarchy for each entity. Removing the project's Root Namespace solved this issue, although it's unclear to me exactly why this was the case.
What I compile in VB on 2019 will not compile on Azure pipeline. So this is a real problem.
I ended up dropping out a project from my solution as I could not reconcile a good solution to the above and it was testing code. In another project I migrated out to a C# library eliminating the issue entirely. It is a VB issue alone.

How do you bootstrap an asp.net application with Ninject for VB.NET?

I've used Nuget to pull in Ninject and the .Web and .Web.Common extensions. It's my understanding that I shouldn't need to touch the global.asax file and only need to register my modules in NinjectWebCommon, but this file is pulled in from NuGet as a C# file, and simply converting it causes errors.
Does anyone have a working NinjectWebCommon.vb file they can share?
I hit the same issue - a legacy VB.NET web application hosting Web API 2 -
"Overload resolution failed because no Public 'ToMethod' can be called
with these arguments"
I've managed to get around this by moving the creation of the Bootstrapper and setting the reference to the Kernel property from being inline, to being performed before the binding:
Dim k = New Bootstrapper().Kernel
kernel.Bind(Of Func(Of IKernel))().ToMethod(Function(ctx) Function() k)
kernel.Bind(Of IHttpModule)().To(Of HttpApplicationInitializationHttpModule)()
Hope this helps,
Scott

Unable to declare variable as IDataObject and Bitmap. codeproject thumbnail images from pdf

I get the source code from here by Jonathan Hodgson
http://www.codeproject.com/Articles/5887/Generate-Thumbnail-Images-from-PDF-Documents
I can run the source code ok
but when I try to write the code in my own project. I cannot declare two types of variable
which is this part
Dim clipboardData As IDataObject = Clipboard.GetDataObject()
and
Dim pdfBitmap As Bitmap = clipboardData.GetData(DataFormats.Bitmap)
The difference I can see is that the code by jonathan has a reference to .net 2.0
and my project is .net 4.0
but changing my project to .net 2.0 does not seem like a good solution
I am wondering why can't I declare as iDataObject and Bitmap?
I can see both iDataObject and Bitmap in object browser in my project, but Why can't I use it?
another difference is jonathan source code is a console application
and my project is class library
thanks you for any response
Verify that you have reference to the System.Drawing.dll in your class library's References folder.
From what I can tell the IDataObject interface is part of the Windows development API, System.Windows.Forms namespace (System.Windows.Forms.dll) for WinForms development and System.Windows namespace (PresentationCore.dll) for WPF development, so verify you have one of those two references in your class library's References folder.
Finally, verify that you have the appropriate Using entries for the above namespaces, like this:
Using System.Drawing

simple vb.net database program

Over 6 years ago I did visual basic programming. I used VB6 for an editor. I did it for a semester in college, and I didnt make a good grade. Since then I have been doing other things in life. However I was asked at work to create a web application. I am creating my application in vb.net 2003. I began desigining the interface of the web form. I have 5 forms, all of them need to connect to a database which I already have prepared. I created the database in MS Access. If I can get one of the forms to look at the database, I think I can get the rest of them to do it. I have tried using beginner tutorials online and I am not finding anything thats helpful. The closest tutorial I have found that could atleast give me an idea of what to do, the code doesnt work, I did everything to the 'T'. http://www.startvbdotnet.com/ado/msaccess.aspx
Is there anyone out there that can help me?
What you are looking for to access Microsoft Accesss Databases (MDB) is the Microsoft JET Client. If you are using a Visual Studio here is the VB for simple access. You can query the database file with SQL.
Outside class
Imports System.Data.OleDb
Imports System.Data
Inside class, to access the database
Dim cn As OleDbConnection
Dim db As OleDbDataAdapter
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder\file.mdb;")
cn.Open()
db = New OleDbDataAdapter("select * from Table1", cn)
Dim ds As New DataSet()
db.Fill(ds)
For Each row As DataRow In ds.Tables(0).Rows
me.txtRow1.text = row("Row1")
me.txtRow2.text = row("Row2")
me.txtRow3.text = row("Row3")
Next
cn.Close()
cn.Dispose()
cn = Nothing
For more information go to, http://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine . Hope it helps!
A 'low barrier to entry' of using an Access DB with VB.Net would be to import the ADODB COM library. Since you've done VB6 before, you should be familiar with the "classic" ADO syntax.
I'm using it right now with a small VB.Net 2008 app and it works perfectly fine. No need to deal with data connections, adapters, fill methods, data sets, or data tables.

Linq-to-SQL datacontext not generating an object

I am working in a .NET 2.0, recently upgraded to .NET 3.5 environment (VS2008, VB.NET) on an existing ASP.NET website project. I am able to generate a Linq-to-SQL Class (also called a DataContext?) in the App Code folder, drag over tables from an active connection, and save it. Let's call it MyDB. When I go to the code-behind file for my page and try to declare an object of "MyDBDataContext" it is not in the intellisense, indicating that it is not accessible.
I checked the references, and that has to be set correctly because I made the .dbml file.
I made a new test windows app project and it behaved exactly as expected, and I could follow this blog without a problem.
Is there something inherent to web projects that doesn't allow for these auto-generated objects to be usable? Is App Code the right place to declare it?
If you can't tell from the above, I am new to the industry and really new to LINQ.
thanks for your help.
Try expanding the dbml file and open the designer.cs file underneath, and make sure the DataContext class is in the same namespace as the codebehind class. If not, either change the namespace or include it with a using Namespace statement the top.
If it your dbml is in a folder inside of '/App_Code/' it may pick up the folder's name as a namespace. Eg: '/App_Code/DAL' would have the namespace 'DAL'. Give it a namespace in the designer or just use the namespace it is given, if this is the case.

Resources