How can I fix LINQ dependency issues with a VB.NET deployment? - vb.net

I have a program that contains .dbml files. I created this file with Server Explorer.
I want to execute this program on other computers but I seem to be having issues with dependencies because I use LINQ.
How can I fix this?

Can you be more specific? What errors are you encountering? Did you use SQL Passwords or Network authentication? Do your users have network accounts added to SQL? Is this a permission based error?
Just one other possibility: Your users should have .NET 3.51 installed on their systems or they won't get the best possible Linq support. They might not have the Linq assemblies at all.

Yeah, we need more info, but I'm guessing you're having problems with the ConnectionString? as in, there's a connection string in your DBML designer file, and it doesn't match your production DB connection string?
If this is the case, then perhaps write a class that handles all instantiations of your DataContext in your code.
Then, within that class, whenever a new datacontext is created, you override the DBML connectionstring with your current connectionstring, probably from your web.config. this ensures your LINQ stuff is always connected to the correct DB during runtime.
Perhaps something like this (the property names might differ):
Public Shared Function GetNewContext() As YourDataContext
Dim dContext As YourDataContext
dContext = New YourDataContext()
dContext.Connection.ConnectionString = MyConnectionStringFromTheWebConfig()
Return dContext
End Function

Related

System.Data.SqlClient Package is installed but isnt recognized as a Using statement in Xamarin Forms app

Like the title says, I've installed both the System and Microsoft .Data.SqlClient SQL packages, and my code only recognizes the Microsoft one, but it doesn't recognize the using System.Data.SqlClient; statement. I've done this process before successfully in a console app, but in the XamForms app it doesn't work. As a result, I cannot use the SqlConnection or SqlCommand or SqlDataReader objects which make it a tad bit difficult to make a SQL database app if ya know what I mean.
I want to put my "login" to my SQL server in a separate file so that I can change them easily should I decide to launch this app publicly. My best guess is that I have to do this in a specific part of the XamForms app, but I don't know where if there is a specific spot. For the time being however, I would just like to get the .Data.SqlClient working regardless of where I put it.
System.Data.Sqlclient has dependencies on libraries that do not exist in iOS/Android. And even if they did, it is a really, really, really bad idea to have direct access from a mobile app to your SQL server. This is how SQL servers get hacked and companies lose their users data and then get sued out of existence.

Change Database-Name/Server at runtime

I am using Visual Studios build-in DataSource functions, to work with my application and its database. Now I am facing one little problem; How do I change the database-server in the final project?
Obviously the end-users server name will not be the same as mine.
Also how can I change it at runtime? My application has functions to find the database-server itself, so it needs to be able to change the database server at runtime (Only at applcations start) .
Update 1:
Right now I am Changing my TableAdapter.Connection.ConnectionString with .Replace("My Local Server Name", "New Server Name") to change the Server. But I don't think that's the way it's supposed to be done.
If you want to change the connection string after deployment then you edit the config file by hand or you can do so in code if the current user is an administrator.
If you want to change the connection string for a table adapter at run time to something other than what's in the config file then you do indeed need to set the Connection.ConnectionString property. The most advisable way to do that is to use a connection string builder. For an Access database, that might look like this:
Dim builder As New OleDbConnectionStringBuilder(myTableAdapter.Connection.ConnectionString)
builder.DataSource = dataSourceName
myTableAdapter.Connection.ConnectionString = builder.ConnectionString

Global Connection from SQL Server Database to VB.NET

I want to create a global connection class from Sql server database to vb.net to make it easy in later editing the connection. Could anyone guide me the way to code both creating and calling to individual form?
Any help would be appreciated. Thanks
Keep your connection string in your web.config file. (this gives you a single point where you can change the connection string without needing to recompile your application, it also allows you to encrypt it in the future to protect your DB server).
I'd advise against using a single "connection" object for reuse. Open and close a connection for each query or transaction.
Check out the Repository pattern instead. http://msdn.microsoft.com/en-us/library/ff649690.aspx

Creating Simple desktop database application

I am here to write a small database application that will be running in desktop (offline mode).
I am using MSAccess 2007 as my database file and trying to write code in vb.net.
I used to write the code vb6 an usually had global variables for storing database connection and executing every query from that.
I am trying to upgrade myself from vb6 to vb.net.
do i need to read some more simple starter books also?
In .NET, talking to a database is handled with ADO.NET, which uses something called "connection pooling". The connection pool is basically a collection of open connections to your database that ADO.NET manages for you. In your code, when you create and open a Connection object, ADO.NET first looks in the connection pool to see if it already has an open connection to your data source, and if it finds one it uses that (instead of actually creating and opening a new connection). When you close your connection, ADO.NET does not really close it, but instead returns it to the connection pool.
Therefore, you do not need (and in face do not want) to maintain open connection objects inside your application (in a global variable or anywhere). The correct approach with data access in ADO.NET is to create and Open a Connection object, do whatever you need to do with the database, and then Close and Dispose your Connection.
Store the connection string in the config file (in the solution explorer, open the My Project folder and doubleclick on Settings.settings).
I'd suggest that you create one or more classes to contain your database code and let those classes convert between the database data and your application objects, most VB6 projects I saw had the GUI hard linked to the DB which can make future maintenance or new features very difficult and limits the possiblity of code reuse.
If you've got VB6 experience I'd thought that you could probably start trying to create the application right away but you should definitely read either a good book or good articles about it at the same time so that you pick up things like that you need to Dispose of your database objects after user etc.
It's probably a good idea to get a book, a lot has changed since VB6.
Also consider using a more robust db, like SQL compact or SQLite. It will allow you you use the Entity Framework which will make writing your app a whole lot easier.

How to set SSIS Http Connection Manager credentials with config file?

Within an SSIS package I have a Web Service task which uses an Http Connection Manager. I need to set credentials for the connection so that it will authenticate with the remote web service. I can set these at design time, however I would like these credentials to be provided to the package using an XML package configuration file.
The problem is that the credentials for the connection do not appear among the properties that can be configured. I have tried setting this programmatically, but I cannot seem to access the credentials that way either:
Dim webConnMgr As ConnectionManager = Dts.Connections("My web service")
Dim webConn As Wrapper.ConnectionManagerHttpClass = _
CType(webConnMgr.InnerObject, Wrapper.ConnectionManagerHttpClass)
webConn.?
Any ideas?
SQL 2005 has very limited member properties for the ConnectionManagerHttpClass. Thankfully it has been addressed in SQL 2008 :)
MSDN - SQL 2005 ConnectionManagerHttpClass properties.
VS.
MSDN - SQL 2008 ConnectionManagerHttpClass properties.
According to this MSDN link, the public class [ConnectionManagerHttpClass] implements IDTSConnectionManager90, ConnectionManagerHttp.
Since we will assume you are using SQL 2005 (according to your Stackoverflow tags), you may want to check out the IDTSConnectionManager90.ConnectionString Property on MSDN as well.
Also check out the ConnectionManagerHttpClass.ConnectionString Property on MSDN, which implements IDTSConnectionManager90.ConnectionString and is overridable.
This should point you into the right direction. May the farce be with you.
Sounds like you need to assign the values in the configuration file to a variable in your package. You can then access the variable from your script task (Dts.Variables("VariableName").Value.ToString if I remember rightly!).
I have found no way to specify the credentials using a configuration file, or programmatically, but a workaround is to simply save all the credentials (as set in the designer) in the package, and then have different copies of the package for each different configuration. This is done by setting the ProtectionLevel of the package to, for example, EncryptSensitiveWithPassword.
This is obviously not ideal.
SQL2008 SSIS exposes these properties correctly; unfortunately 2005 is the environment I have to work with. I have worked around the problem by developing a custom component which allows the properties to be set.
this can be done by setting protection level to EncryptSensitiveWithPassword, and run the ssis with decrypt option