Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am searching to convert a entire database into a text file and access the file via a windows form application. If it's possible then help me how to make it.
You can use Generate Script option in SQL Management studio to generate script for selected objects. There are option to make script of 'schema only' or 'data only' or 'both'.
Step 1: Right click on your database then navigate to task >> Generate Script
Step 2: Click Next
Step 3: Since you want to generate script for whole database. so default option is ok. Otherwise you may select the particular database objects.
Step 4: Select appropriate option from advanced popup.
Step 5: Click next and your database script is generated as your selected option.
Please find this link for detail steps for generating script in SQL Server Generate Scripts.
There you find your option to save generated script in query window or clipboard or 'sql file`. Which further open in text editor for further use.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
The community reviewed whether to reopen this question 10 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I have data in an Excel file - actually XLSX format since it is now 2020. My requirement is to get this data into SQL Server as follows:
ad hoc, the use case being feeding tables with test data, or infrequent data loads of small amounts of data (say < 3k rows), and
In a repeatable, robust, and possibly automated way for a production system.
There are many articles about writing code to import an Excel file, but this is a manual/shortcut version:
If you don't need to import your Excel file programmatically using code, you can do it very quickly using the menu in SQL Server Management Studio (SSMS).
The quickest way to get your Excel file into SQL is by using the import wizard:
Open SSMS (SQL Server Management Studio) and connect to the database where you want to import your file into.
Import Data: in SSMS in Object Explorer under 'Databases', right-click the destination database, and select Tasks, Import Data. An import wizard will pop up (you can usually just click Next on the first screen).
The next window is 'Choose a Data Source'. Select Excel:
In the 'Data Source' dropdown list, select Microsoft Excel (this option should appear automatically if you have Excel installed).
Click the 'Browse' button to select the path to the Excel file you want to import.
Select the version of the Excel file (97-2003 is usually fine for files with a .XLS extension, or use 2007 for newer files with a .XLSX extension)
Tick the 'First Row has headers' checkbox if your Excel file contains headers.
Click Next.
On the 'Choose a Destination' screen, select destination database:
Select the 'Server name', Authentication (typically your sql username & password) and select a Database as destination. Click Next.
On the 'Specify Table Copy or Query' window:
For simplicity just select 'Copy data from one or more tables or views', click Next.
'Select Source Tables:' choose the worksheet(s) from your Excel file and specify a destination table for each worksheet. If you don't have a table yet the wizard will very kindly create a new table that matches all the columns from your spreadsheet. Click Next.
Click Finish.
You can also use OPENROWSET to import an Excel file in SQLÂ Server.
SELECT * INTO Your_Table FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\temp\MySpreadsheet.xlsx',
'SELECT * FROM [Data$]')
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I have a database backup file named iyym.bak. How can I attach the database to my SQL Server 2008?
I tried inside SQL Server Management Studio the following:
right click on data base folder in object explorer
selected attach
click add button.
When I am trying to add the backup error showing iyym.bak is not a primary database.
I have used the same version of SQL Server to take the backup too.
How can I attach this back?
A .bak file isn't supposed to be ATTACHED. It's a backup file that you RESTORE.
Try something like the following:
RESTORE DATABASE [DbNameGoesHere] FROM DISK ='C:\PathtoBackup\Backup.bak'
Here's the MSDN article that has all the switches and arguments:
https://msdn.microsoft.com/en-us/library/ms186858.aspx?f=255&MSPPError=-2147217396
You cannot Attach an SQL Server Backup File.
Instead, you need to create a new empty database, and them restore the backup on top of it. Just make sure to replace the MDF and LDF Path a file name to match your new DB files, and to check the option WITH_Replace.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
At my job, I occasionally have to perform the following tasks:
Use Remote Desktop Connection to log on to a server.
Copy a set of files from a specific folder on my computer to a specific folder on the server.
Execute an SQL query on the server in SQL Server Management Studio, copied from a text file on my computer.
Log out of the server.
And then repeat for a whole bunch of other servers. This adds up to more than an hour, and I'm trying to figure out a way to automate it. What's the best way to go about doing this? I don't think Windows is as feature-rich as Linux when it comes to the command line, and I'm inexperienced with network protocols as it is.
You can automate this kind of behavior using batch files and scheduled tasks.
You can install the Command Line Utilities 11 for SQL Server from here:
http://www.microsoft.com/en-us/download/details.aspx?id=36433
And find reference material for the utilities it offers here:
http://technet.microsoft.com/en-us/library/ms162816.aspx
You will want to write a batch file that executes your actions in order. I recommend running a non-lethal SQL query against a test database while you develop your batch file, but it will be something like this:
::Copy the files
xcopy "\\server\c$\Source\*.*" "\\server\c$\Destination\"
::Set your MS SQL variables
set /p SName="Server Name"
set /p UName="User Name"
set /p Pwd="Password"
set /p DbName="Database Name"
::Execute your SQL query
sqlcmd -S %SName% -U %UName% -P %Pwd% -d %DbName% -i "c:\sqlCommand.sql"
Then you'll want to set it up to run as a Windows scheduled task by a user account (or service account) that has access to both of these network locations.
That should do the trick.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm using VS2010 as a client for a TFS instance. I created a workspace, and need to map a TFS directory to a local directory - let's call the local directory "D:\aaa\bbb\ccc\ddd". When I navigate to "Manage Workspaces" and click "edit" to change the local directory to this path, I am presented with the following error: 1
This error occurs when I try to map: "D:\aaa", "D:\aaa\bbb", "D:\aaa\bbb\ccc".
Now, if I create a folder called: "D:\aaa\bbb\ccc1\ddd", the mapping works, and I do not receive this error.
Can anyone help? I've been pulling my hair out for about a day over this.
Thank you.
[EDIT01: I tried mapping all other folders under the D:\ drive, and only one other folder fails the mapping. I receive the same error as with "D:\aaa\bbb\ccc\ddd" ]
SQL Errors
First of all, you should not be receiving SQL Error 18054 (or any SQL errors) from TFS.
You should have your TFS administrator connect to the SQL server that hosts the master DB for your TFS server and run the following query:
select * from master.dbo.sysmessages where error > 50000
If this is a TFS2010 server, your TFS administrator may be able to use TFSConfig PrepSql to re-install the error messages.
If this is a TFS2008 server, your TFS administrator will need to open Add/Remove programs and run a repair on TFS.
Your actual problem
This sounds obvious at first, two
local paths cannot point to the same
place in the repository for the same
workspace. However, the one that
catches a lot of folks un-aware is
that you cannot have two repository
paths mapped to one local path on the
same computer.
In TFS, you cannot have two folders with overlapping mappings. Since D:\aaa\bbb\ccc\ddd is a sub-folder of D:\aaa, then you cannot add it.
One thing you can do though, is cloak folders so that they aren't part of the workspace mappings. In your case, you might want to map D:\aaa and add a cloak for all the other subfolders in that directory, except for D:\aaa\bbb.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a batch file on a Windows 2008 server that, when invoked from command line works fine. However, when I set a scheduled task to run this job, it does not work properly.
The task scheduler does show that that the task is getting run at regular intervals, it does not show any error. But, the batch file does not process what it is supposed to process.
Any ideas on how to fix this issue is most welcome
Windows Server 2008 will not run any batch file with quotation marks " inside the batch file.
See http://technet.microsoft.com/en-us/library/dd851678.aspx
I had a similar problem, my .bat file wouldn't correctly execute when I had the full file path in the "Program/script" field.
"D:\path\to\file\somebat.bat" didn't execute. (with quotes)
When I put D:\path\to\file\ (without quotes) in the Start in (optional): field and somebat.bat in Program/script: field somebat.bat executed correctly.
Go figure... not exactly sure why having "D:\path\to\file\somebat.bat" in the Program/script: won't work.
Maybe someone could shed some light on that?
In my case, I had 'Run whether user is logged on or not'. When I changed to 'Run only when user is logged on' it worked OK.
Make sure the task is running under an account with the necessary privileges. When you run a batch script from the command-line directly, it is running under your user account, which may have different permissions than the default account used for scheduled tasks.