I'm new to EF Core and SQLite and I followed the steps at https://learn.microsoft.com/en-us/ef/core/get-started/uwp/getting-started. Everything works just fine in C#, however when translating it to VB, I get the following exception:
Microsoft.Data.Sqlite.SqliteException: 'SQLite Error 1: 'no such table: Blogs'.'
I've tried changing the "Data Source=Blogging.db" to an absolute path, but if I do I get
Microsoft.Data.Sqlite.SqliteException: 'SQLite Error 14: 'unable to open database file'.'
This is what I am using right now (in the context):
Protected Overrides Async Sub OnConfiguring(optionsBuilder As DbContextOptionsBuilder)
Dim AssetsFolder As StorageFolder = _
Await Package.Current.InstalledLocation.GetFolderAsync("Assets")
optionsBuilder.UseSqlite(String.Format("Data Source={0}", _
Path.Combine(AssetsFolder.Path, "blogging.db")))
End Sub
And in the App.xaml.vb:
Sub New()
InitializeComponent()
Using db = New BloggingContext()
db.Database.Migrate()
End Using
End Sub
Any help would be much appreciated. If you require more info, please let me know and I'll gladly provide it.
Crix
The problem seems to be due to the created .cs files. When you convert the three files to .vb files, the desired tables are created and an entry is created in the EFMigrationsHistory table. I have manually converted the following files from cs to vb:
20170819131117_Inital.cs
20170819131117_Inital.Designer.cs
DB_ModelModelSnapshot.cs
And the cs files taken from the project and the vb added. If someone now knows how to run the add-migration command for vb, that would be very helpful.
Related
Hello I am very new to Visual Basic and have almost no clue what I am doing. I have encountered an issue saying the following.
openFileDialog1 is not a member of windowsapp1.my
I can not seem to fix it. Here is my code:
Public Class Form1
Private Sub Form1_Load()
Dim OpenFileDialog1 As New OpenFileDialog
My.openFileDialog1.Title = "Please select a DB file"
openFileDialog1.InitialDirectory = "C:\"
openFileDialog1.Filter = "DB Files|*.extensionHERE"
End Sub
End Class
I have tried to no avail to fix this and so I hope that some one can help, thanks!
I think you're mis-reading what the examples are saying. When you read tutorial/example code, where it lists "OpenFileDialog1," for example (or DataGridView1, etc.) that refers to whatever name you are using for your particular OpenFileDialog1 control. If you had multiple openfiledialogs in your code, having them all named OpenFileDialogN can get confusing it a larger application. Using a meaningful name is a good practice.
Using the "My" isn't necessary in your code snippet. In VB, the "My" refers to a namespace indicating the system on which the application runs. Since all your code is doing is opening a file dialog, that isn't necessary.
Check out this handy doc by MS: https://learn.microsoft.com/en-us/dotnet/visual-basic/developing-apps/development-with-my/index
I try to use my own .dll in a script compoment within ssis. The normal procedure gives me an error: "could not load file or assembly 'xxx' or one of its dependencies. The system cannot find the file specified."
What I tried yet is I went to project -> Open in Explorer and put my .dll into the bin folder but that same error occures.
I found this C# Code and converted it to vb.net:
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute> _
Public Partial Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Shared Sub New()
AppDomain.CurrentDomain.AssemblyResolve += New ResolveEventHandler(AddressOf CurrentDomain_AssemblyResolve)
End Sub
Private Shared Function CurrentDomain_AssemblyResolve(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
If args.Name.Contains("ssisHelper") Then
Dim path As String = "c:\temp\"
Return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "ssisHelper.dll"))
End If
Return Nothing
End Function
End Class
But I do not have Micorosoft.SqlServer.Dts.**Tasks**. Anyone who can help me either get this script working or can provide another solution to get my dll running within the script compoment?
And before adding it to the GAC you need to strong name it, example here: http://microsoft-ssis.blogspot.com/2011/05/referencing-custom-assembly-inside.html
You need to add the assembly to the GAC (Global Assembly Cache) by running gacutil -i assembly.dll
More information can be found here
https://msdn.microsoft.com/en-us/library/dkkx7f79(v=vs.100).aspx
I'm creating a html page that will import an excel file in to a tracking system. On a button click event excel file is located / ssis package is fired / data imported then closed out. Thats the idea work flow. Problem is the excel file access is being denied before the package even executes
Here is the exact error :
I've tried :
excel file properties have been shared to everyone
identity impersonate set to true
hard coding the path
here is the VB code
Protected Sub bntExecute_Click(sender As Object, e As EventArgs) Handles btnExecute.Click
Dim app As Application = New Application()
Dim package As Package = Nothing
'Dim fileName As String = "C:\Users\Desktop\T. Bryant III\PTSID_Update_Template"'
Try
Dim fileName As String = Server.MapPath(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName.ToString()))
FileUpload1.PostedFile.SaveAs(fileName)
package = app.LoadPackage("#C:\Users\Desktop\T.Bryant III\KitImport", Nothing)
'excel connection from package'
package.Connections("SourceConnectionExcel").ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0data source =" + fileName + "Extended Properties = Excel 8.0"
'Execute the pakage'
Dim results As Microsoft.SqlServer.Dts.Runtime.DTSExecResult = package.Execute()
Catch ex As Exception
Throw ex
Finally
package.Dispose()
package = Nothing
End Try
End Sub
Thanks in advance or if there is an easier way to do this please let me know. The package when executing it in ssis works fine with its own connection manager etc.
A few things to try. If they don't work for you as permanent solutions, they should at least confirm that your code is working and you are dealing with a persmissions issue (which appears to be the case).
Move your file to the public folder (C:\Users\Public).
Run your application (or web browser) as an administrator (if applicable to your version of Windows).
If you are using a web browser, try using a different one.
If nothing else works, try pasting your code into a Windows Form Application.
If you still get the same error after trying all of this, it's time to take another look at your code. Remove the Try/Catch block to determine precisely which line is throwing the error. If you've tried hard coding, I'm guessing it's the SaveAs method. I'm not sure what class FileUpload1 is, but some SaveAs methods won't overwrite existing files unless you explicitly tell them to. Check the appropriate documentation and see if you don't need to pass a True value somewhere along with filename.
Update us with the results. At the very least, this should narrow down your problem and allow for a better diagnosis of it.
We have created a workflow process as an SSIS package and would like to find a way of gaining access to this code so that through vb.net we can dynamically access and run that code. For example, we would like to change the data sources being used, or change the column mappings of existing packages and then execute them from a vb.net application. Please advise the best way to do this.
You will find some of your tasks easy, others not so much.
Generally speaking, you'll be interested in reading the Developers Guide to Integration Services. Of particular interest will be Building Packages Programmatically and Running and Managing Packages Programmatically.
For example, to run a package from VB.NET
Imports Microsoft.SqlServer.Dts.Runtime
Module Module1
Sub Main()
Dim pkgLocation As String
Dim pkg As New Package
Dim app As New Application
Dim pkgResults As DTSExecResult
pkgLocation = _
"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services" & _
"\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx"
pkg = app.LoadPackage(pkgLocation, Nothing)
pkgResults = pkg.Execute()
Console.WriteLine(pkgResults.ToString())
Console.ReadKey()
End Sub
End Module
To change the connection manager programmatically, it'd be the VB.NET equivalent of
ConnectionManager item = ep.Connections["MyConnectionManagerName"]
item.ConnectionString = #"Provider=SQLNCLI10.1;Data Source=Server1;Initial Catalog=ABC;Integrated Security=SSPI;";
Changing column mappings, that's where it's going to get interesting, for all definitions of the word interesting. I'm have a distilled example but it takes some work and you'll want to really understand the whole object model (and I hope you like COM). EzAPI might be of some assistance in that area.
sorry for long text.
Problem: I have difficulty in removing the LDB generated by the "CREATE" method of ADOX in the following code segment. Please provides some hints/pointers to the solutions, and thanks.
Aims: Create (on the fly) a new access database and then export data (says Arena modules) to that newly created database.
Expected: The newly created access database should be able to be used by some external operations, say Access.exe, after the end of the subroutine and without exiting the current VB program.
I tested that the "Arena code" do nothing about the create/release of the ldb file.
I tested the "Exclusive Mode" in connection string, but the access file is still locked by the vb program.
I tested under both inside the VB environment, and directly invoke the generated from Explorer, and same results.
Other database formats is not the options to me. (due to Arena export limit)
It is not a web app.
Code:
Sub Method1()
Dim logs As New System.Collections.Generic.List(Of String)
Dim arenaApp As Arena.Application = Nothing
Try
logs.Add("Creating access database")
Try
Dim cat As New ADOX.Catalog
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=new.mdb;Jet OLEDB:Engine Type=5")
cat = Nothing
Catch ex As Exception
logs.Add(ex.Message)
logs.Add(ex.StackTrace)
Finally
logs.Add("End creating access database")
End Try
'Opening Arena model"
arenaApp = New Arena.Application()
arenaApp.Models.Open(fileName)
arenaApp.ActiveModel.ExportModules("", "new.mdb", "TableName", "", Arena.smExportType.smExportAll)
Catch ex As Exception
logs.Add(ex.Message)
logs.Add(ex.StackTrace)
Finally
...
End Try
End Sub
Platform:
Windows 7 64bit, Office 2010 (32)
VB 2010 express
Lib: MS ADO Ext. 2.8 for DDL and Security
What about closing the mdb after creation, then reopening it ?
I am not a VS expert, but in Access, many things in "Design mode" put the mdb in Exclusive mode...and you can't switch back without closing it first i suspect.
If you want to create a database, its probably simpler to PInvoke SQLConfigDataSource. Then you can connect to it via ADODB, ADO.NET or your VB.NET data access methodology of choice.
I don't have an example of doing it in VB.NET, but this C# class and this powershell script demonstrate how to call the function.
I know it's an old question. I encountered exactly the same issue today. Some comments ask why use ADOX, that's because first, it's from legacy code, and second, I didn't find any other ways to dynamically create mdb file.
In VB6, whenever you set adox = Nothing, this com object will be released immediately and so is the ldb file.
In .Net, you have to rely on GC to collect the adox before ldb file is unlocked.
So, I made the following trick. I know it's ugly, but I didn't find any other ways, and at least my trick worked.
Dim t As New Thread(
Sub
'All adox code should be here
'....
'....
adox = Nothing
End Sub
)
t.Start()
t.Join()
t = Nothing
GC.Collect()
Sleep(50)