Updating a SQL server from a remote .dbf file - sql

I currently have two servers. One is a server with .dbf files that get updated very frequently, and the other is a server with SQL Server workgroup edition on it.
Problem: I need to update the SQL Server tables from these remote .dbf files, how is it done? I need these files to be pulled automatically from the server every X amount of hours.
Research thus far:
I believe I understand how to update tables having the .dbf file on the same server as the SQL Server database, you would use the DTS management studio provided with SQL Server. I don't believe this solution would work trying to pull these .dbf files remotely. I have looked into a Linked Server, but don't understand what that really is. These .dbf files come from a visual foxpro server. As far as i know visual foxpro has no interface like SQL? If anyone has any advice in order to point me into the right direction, this would be much appreciated. I can usually find the answers, but feel pretty helpless on this one... Thanks in advance for any effort put into this problem.

A linked server is basically just a pointer that lets the code within your database interact with external data sources as if they were also within your database/instance. There are some examples here for creating linked servers to FoxPro DBFs:
http://fox.wikis.com/wc.dll?Wiki~VisualFoxProDataFromSQLServer
So for example if you had a linked server to a FoxPro database called MyFoxProDB you could run a query within SQL Server like this:
UPDATE t
SET t.foo = x.bar
FROM dbo.LocalTable AS t
INNER JOIN MyFoxProDB...TableName AS x
ON t.key = x.key;
You could also consider using OPENROWSET as described in this question:
Import DBF files into Sql Server
(But personally I think the linked server will be a lot more flexible.)

Related

Generate Scripts in SQL Server (big files)

I am in process of moving my database from SQL Server 2012 to SQL Server 2008. Since I can't just restore them like if I was moving from 2008 to 2012 I have to use generate scripts for data and schemas.
Problem is I have some HUGE database files. One of the files generate becomes 19gb. There does not seem to be any way to move this file because I think the size itself makes the file corrupt. I cant open the file in the SQL Server Management Studio and even using the .bat script it fails (it just freezes). My other tables I have no problem with but they are much much smaller.
What could fix this would be if there was a way to split the data up in several files like each file is 100mb or whatever, then I could make a script that would execute them all, but is this possible?
If not what do you guys suggest?
I would suggest you create a database with the same name in SQL Server 2008 (and possibly tables) and try to do a replication between the two database with SQL Server 2008 as the subscriber, just once should do
If you have the ability, you could also try creating a linked server entry on the 2008 box that points to the 2012 one. Then, you can use the four part fully qualified name (server.database.schema.table) to SELECT the rows from the 2012 instance and INSERT them into the 2008 instance.

What does Microsoft SQL Server do?

I understand that this is painfully generic and broad. Nonetheless, all the answers on wikipedia and yahoo (none here that I can find) are pretty useless.
I know T-SQL, C#, etc to some degree. I understand the idea of a database. However, I have NO idea what I created when I made a "server" on my computer through Msft SQL Server. Now I can make databases on that server, and I can connect to them with Visual Studio (sometimes) to use with LINQ or "raw" calls.
Please help me understand (or direct me to an article) of what this myComputerName\SQLEXPRESS (SQL Server xx.x.xxx) thing is. I assume the databases are stored locally...somewhere. SQL Server provides access to the DB files? Why can't they be accessed directly?
Thank you if you even read all this. I really can't narrow the question down.
I guess one specific question is "Can I access the databases without SQL Server running?" Where do I even get the connection string?
You are asking multiple questions, here.
However, I have NO idea what I created when I made a "server" on my
computer through Msft SQL Server. Now I can make databases on that
server, and I can connect to them with Visual Studio (sometimes) to
use with LINQ or "raw" calls.
Please help me understand (or direct me to an article) of what this
myComputerName\SQLEXPRESS (SQL Server xx.x.xxx) thing is.
The layout of a database server is as follows:
Server
Instance a
database aa
database ab
...
Instance b
database ba
database bb
...
...
So, when you install MS SQL Server, you install a MS SQL Server "instance". In this "instance", you can create a number databases. Each database has database files, the exact location of these depends on the settings you chose during installation.
I guess one specific question is "Can I access the databases without
SQL Server running?"
You do not usually open dbf(mdf -ldf) files (the database data files) without MS SQL Server, why would you want to ? You should use the backup/restore features inside MS SQL Server.
Where do I even get the connection string?
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.110%29.aspx
The "server" is a process/service running on your computer which can be connected to over the network and provides the API to access your database.
"Why can't they be accessed directly?" Is like asking why do I need Word to view Word files, can't I use Notepad for that. Sure you can, but not really.
Another reason is - imagine multiple processes need to access the database. If each reads and writes to the same files, something WILL break if they don't coordinate. Having a separate server process encapsulates all this.
"Can I access the databases without SQL server running?" I mean yes but actually no.
If you want a database that your program accesses directly (or let's say, your program is also the database server in a sense) - then you can use sqlite, or for simple tasks there are also ODBC drivers for CSV, so you can use CSV files as if they were a database. A dedicated SQL server is always better for bigger more complex tasks and data models though.

How can I move data from one SQL Server to other?

I want to copy all my database to remote database server. I have access to server using SQL server management studio.
How can I do this? I have created script with data of old database and tried to run it on new server but it is taking too much time and returns different errors like duplicate key etc.
If this is a one time deal, you should download Redgate's SQL tools. They can handle this easily and are free to test for 14 days I believe. (http://www.red-gate.com) You might even find they are worth the purchase as I have. The tools you would use are SQL Compare (to copy structure) and SQL DAta Compare to actually copy the data.
Assuming that you can restore databases to your remote SQL server, you can use SQL Server backup and restore? They're available in SQL Server Management Studio. See http://msdn.microsoft.com/en-us/library/ms187510.aspx. It's very easy to use.
Other than that, you can try copying the database MDF and LDF files from your local database onto your remote database filesystem, then attaching to the MDF file on your remote database.
Those are probably the fastest ways that you can copy and entire database to a remote location that I can think of.
Try Database publishing wizard by Microsoft. Good enough for no very big data amounts.

How to automate a Visual Studio/SQL Server report

I'm currently working on a reporting tool for a company that conducts the same survey at different clients. So the analysis and report would be the same, except for the conclusions. The ultimate goal of the project would be a tool that automatically extracts, analyses the data and creates the report. SQL Server and Visual Studio are mandatory programs.
I'm completely new to all of this except for the SQL-language. After reading up on this and asking around the usage of stored procedures seemed the best option. If I interpret correct these should be stored in SQL Server and could then be envoked in Visual Studio
However, my problem is, I can't figure out how to connect to the external ODBC-server that holds the data in SQL Server 2005. It seems to me there is no way to connect to a remote server in SQL Server 2005. On the other hand, in Visual Studio 2005 I did manage to connect and extract data from the server.
Is this the right way to achieve my goal (repeatable/automated report)? If so, what am I doing/thinking wrong? If not, please enlighten me.
Thx in advance
Another way to do this is to use bcp...you can check this article to see if there are any answers here for you. There would be no remote server connections if you are able to run the command and the local box that contains the sql server.
You might be able to set up a linked server in SQL Server 2005 to connect to your remote server/database.

Partial import of Sql server 2005 database for local developement

So at work, my team is using a central SQL server 2005 database server for integration testing and I want to move to testing on my local database. The only problem is that the central database is in excess of 10 Gb.
I am interested in importing the data objects and a rows for each table to ensure I can be up and running. Can you guys advise me on how I can do this?
I have VS 2008 professional and SQL Server management studio express. Would I need VS 2008 database edition?
Thanks
-Venu
EDIT : I will try logging into the central database server and seeing if the host machine has better tools. Thanks kpollock, I didn't think of that.
Both 2005 and 2008 Express editions have 4 gb limitation.
Have you thought about making a db copy on central server and dealing with it (just restore it into new db with other name)?
See also BACKUP and RESTORE in SQL Server -- Full Backups
Looks like an SSIS job to me - which I think Express version of Management Studio doesn't have.
Or you could do it in C# calling Stored procs on the source database to extract the data if that's where your skills lie. (this is how I would do it as I think it's more widely comprehensible - but that's just my opinion).
If the database is live and new data comes in all the time perhaps you could set up the schema and reference data only then use replication to get the new data as it comes in (if you think that will get you a representative sample).
You will have to code up the sample extraction based upon an understanding of the schema - i.e. ensure you get a full set of linked records (e.g detail records for orders and all lookups e.g. customer, addresses, etc.).