How to get LinqPad DB connections to work across multiple computers? - linqpad

I have many LinqPad scripts I use to query databases. These files are all in dropbox so I have all my queries available across computers. Very handy.
However each script is tied to a database connection, and that connection does not work on different computers. I'm guessing it has to do with how the passwords are stored. Is there a way to get the db connections in the linqpad scripts to be valid across different computers?

After opening the query on another computer, right-click the connection that automatically appears in the Schema Explorer, update the password, and click 'Remember this connection'.
This saves the connection details to your local computer, which takes precedence over the connection details stored in your query.

Related

Linqpad DB connections - get it to NOT connect when I open a file?

I have many LinqPad scripts I use to query databases. These files are all in dropbox so I have all my queries available across computers. Very handy.
However each script is tied to a database connection, and that connection is not valid across computers. I'm guessing it has to do with how the passwords are stored. And that's OK.
But what is annoying is when I open a script, LinqPad attempts to connect to the invalid database. It is frozen while this happens. Once it is done, all I have to do is change it to the new db and it's fine. But this freeze interrupts my flow.
Is there a way to tell Linqpad to NOT try to connect when I open a file?
you can use a connection by connection string
so you can add some read key or any machanics to execute connection
using(TypedDataContext context = new TypedDataContext(Connection.ConnectionString)){
context.table.Where(w=>w.ID == 123);
}

Microsoft Access ODBC Connections: Connection String Differences

Using the following:
MS Access 2016, Office 365
SQL Server 2012
I have 100+ SQL Server tables and views linked into an Access database via ODBC connection. All of these SQL Server objects are from two SQL Server databases that reside on the same server. All of these connections have been set up using the Access user interface and re-linked via the Linked Table Manager.
I've been experiencing a number of Access database issues lately, so I’m combing through everything with a fine-tooth comb. I noticed that the connection strings for all my SQL Server objects have a number of inconsistencies (see below). There does not seem to be any pattern in terms of when these objects where created and the format of the connection string either.
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2010;
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=Database1
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=Database1;Network=DBMSSOCN
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2016;
ODBC;DSN=Database1;Description=Database1;Trusted_Connection=Yes;APP=Microsoft Office 2016;DATABASE=Database1
ODBC;DSN=Database2;Description=Database2;Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=Database2
ODBC;DSN=Database2;Description=Database2;Trusted_Connection=Yes;APP=Microsoft Office 2016;DATABASE=Database2
Is it problematic that there are so many variations of the connection string? I've done some research (i.e., Googling), but I don’t much experience in this area of databases. Some connections have a "Network" specified, but others don’t. Per connectionstrings.com (https://www.connectionstrings.com/define-sql-server-network-protocol/), “Network=DBMSSOC” specifies a Winsock TCP/IP connection, which I believe is the appropriate choice for my network setup. Is it problematic that this parameter is excluded from several of the connection strings?
I would most certainly “harmonize” all of the linked tables to the same connection.
You can use the linked table manager to do this, but likely code is better.
You need to select all tables in the linked table manager, and MAKE sure you click on prompt for new location. This will force you to create (or select) an existing DSN. In fact, I would select all tables from the “one” given database, and then click on the “always” prompt for new location. When you do this, then all will posies the SAME link and connection string.
There are good number of reasons, one good reason is Access will cache the connection for you. So if you have “different” connections for the same database, you will have multiple caches of those connections. This likely will not affect performance “much”, but it still a good idea.
And if you are NOT using a trusted connection, then your connection strings in fact do NOT need to include the uid/password. (However, the cache of the uid/password requires exact string matches (minus the uid/password). In this approach, you can execute a “one time” logon on application start up, and then all linked tables (without the uid/password) will now work. However, you using trusted connections here, so this tip + issue don’t matter.
In your example, you using trusted connections, so issues are “much” less of a worry or problem.
I also STRONG suggest that when you launch the ODBC manager from Access, that you ALWAYS but ALWAYS use a FILE dsn. The reason for this is that then Access will convert the connections to DSN-less for you.
This means that you can now deploy the front end application to any workstation, and you don’t need to setup or have any DSN connection copied, or even setup on the workstation.
So I would in fact select all of the tables for one given database, (check the prompt for new location), and then create a FILE dsn (they are the default anyway). Once you link, then do the same for all the other tables that point to the other database. Again re-link.
The result will be a dsn-less connection, and thus your application will work on any workstation on the network, and do so without having to setup a dsn of any kind on each workstation.
So yes, you don’t have to, but it seems over time, some tables were linked using a different DSN, they should be harmonized. And if you ever introduce some automatic linking code, you want to be able to distinguish between the two databases, and you code will have a rather difficult time doing this with a “hodge” podge of differing connections.
So you can use the linked table manger to harmonizing the connections – just ensure you select all tables from a single given database, and then re-link with a FILE dsn, the result will be a DSN less connection (access will ONLY use the DSN during the linking process – after that, access don’t care, nor does it use or even look at the DSN, or even if it exists.
Having said all of the above, it not clear if this issue is related to your errors, or instabilities in your application. (a good idea is to always distribute a compiled version of your application - (a accDE as opposed to accDB).

Distributing .mdf files to field sites

I am trying to find the best procedure to get data from our SQL server at headquarters to update apps running on local machines in various locations not connected to our network. Our current data and application is in Foxpro where you simply copied the data file, so I am not very familiar with using SQL databases.
The field app uses localdb and users don't save anything to the database. When the app opens it checks a web site to for updates. I tried detaching our HQ .mdf and .ldf, downloading it and overwriting it on the local machine, but localdb would not attach to the new file (same name). I thought localdb closes and detaches when the application closes , but maybe I am wrong. I also wonder if I need the log file since no changes are made and I dont need to rollback anything. I have searched for a good article on this topic but haven't found anything. This must be a fairly common scenario in many companies.
You want to look into using replication, probably snapshot replication. This allows you to distribute on whatever schedule is applicable to send one or more tables, or other objects, to off site sql server instances. You can use Http to send data.

How do I connect a VB.net program to a access database and run it on 2 different PCs.

I have a windows application written in VB.net. After finishing it I'll setup the program in more than one pc. I want to connect the program in all PCs to one database in another PC using Microsoft Access, and I also want to limit the level of access of the users to the database in my program.
How can I do it? Many thanks.
Access is capable of handling multiple users, however once you get over 3 or 4 concurrent users you will start to notice that MS Access doesn't scale well. Access is designed for the professional but not an enterprise.
Microsoft SQL Server (Express edition is free - upto 4GB space) is designed for a large number of concurrent users.
I also want to limit the level of access of the users to the database in my program.
You can use folder Permissions if you wish to restrict access to the file. Personally in my old VB6 apps that used MS Access I called the file db.resources rather than db.mdb. This is because a.resources file cant be downloaded if it is hosted online (ref DotNetNuke) and also so people dont know which program to open the file in.
If you need role based security you need a enterprise level database such as SQL Server.
I want to connect the program in all PCs to one database in another PC using Microsoft Access.
Here is how you can have two computers share the same database.
a. Choose the main PC that will host the database
b. Host the database in a folder that is shared to the other users
c. Physically go over to the PC that isn't hosting the database, create a text fileon the desktop.
d. Rename the file extension from .txt to .udl and press enter
e. Double clcik the udl file and enter these settings and navigate to the shared folder that hosts the shared database:
f. Once the Test Connection is successful, close the Data Link Properties window.
g. Right click the UDL file on the desktop and choose Open With and open with notepad
h. You will see your connection string:
[oledb] ; Everything after this line is an OLE DB initstring
Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=\\PCName\c$\temp\Database1.accdb;Persist Security Info=False
i. Set the second pc to use the networked connection string.
Access is perfectly capable to handle 2 users connecting to the same database. However this is not the main strenght of Ms-Access. So, if you plan to grow the user base it's better to start from the beginning with SqlServer Express (or MySql).
You don't need to use asp-net for this scenario if the user are on the same local network.
You are only required to prepare a valid connection string to identify the network location where you install the database. Of course, the PC hosting the database should share the network location and give read/write permissions to all users requiring the access to the database. (This could be the most complicated part depending on where you share the database)

Lotus Notes ODBC Connection

I need to connect and send/receive information from an MS SQL server in my Lotus Notes app using #formula in realtime (I can connect using an agent, but I need to use inline code for this).
The commands themselves seem pretty straight forward, but setting up the configurations seems to be a topic with scarce documentation. Apparently I need to install an ODBC driver. Where would I find that, and do I install that onto the server or onto the workstations that will run this app?
If any Lotus gurus could step me through setting this up, it would be greatly appreciated.
Thanks
You'll need to install the ODBC driver on the workstations that run this app, if the users will be triggering the ODBC connections. If at all possible, I highly suggest setting this up on the server side, and having it run via an agent. That'll save you from a few headaches, including having to maintain the ODBC connections on each workstation and worrying if each workstation has access to the data and server.
You first just want to make sure your ODBC setup is correct. You'll need the appropriate driver, of course, and the connection information. This site has a walkthrough to give you an idea of how to setup an ODBC database connection
If you have MS Access you can use it to test querying from the ODBC data source. Once you've tested the connection works, you'll just refer to the data source name (DSN) in your #DbColumn, #DbLookup, or #DbCommand formulas.
Back to my suggestion on setting this up on the server side, that would mean you'd keep a copy of the data you're querying within the Notes database itself, and then users would be interacting with read-only data in Notes. You could schedule updates regularly on the server side of that read-only data and effectively create a cache of the data in your Notes environment. Then that data would replicate around to other replicas of the database, but remove the trouble of the ODBC connection being needed everywhere.
If you need realtime data, though, that solution is out the window and you'll have to go with a local solution. In that case, you might want to look at the LCConnection class or using an ADODB.Connection from script, as both will allow you to create DSN-less connections to data sources. You'd then save the trouble of requiring ODBC data sources on each workstation, and only have to worry about whether they can access the server from their workstation.
I would add another option to Ken's list. It involves having the server do the queries of the external database (therefore you are only setting up ODBC in on the server - you don't have to deal with it on the workstations). You create an agent that is launched on the server using the 'run on server' technique. When the workstation needs to query the external data, the code creates a throw-away document in the database, puts the query criteria into the temporary document, saves the document, then calls the 'run on server' agent passing a reference to the temporary document. The server launches the agent, reads the criteria from the temporary document, does the query, and writes the results back to the temporary document. Then the workstation can access the query results from the temporary document. A scheduled agent can delete the temp docs on a regular basis.
It sounds complicated, and it all has to be done in script, but I've done this in many applications and it is fast, flexible, easy to administer, and gives your applications a lot of power. Note that end users must have the ACL rights to create a document in the db (the temp doc) in order for this to work.
Good luck!