sqlcmd

How to use sqlcmd to create a database

佐手、 提交于 2019-11-30 11:59:12
I have a .sql script and I want to build a database from it. How to do it in sqlcmd? I know it's like: CREATE DATABASE dbName GO But how to specify the .sql script and location to build the database? Use @Jeremiah Peschka's answer to supply the sqlcmd utility with the script to execute. As for the location for the newly created database, it can be specified as part of the CREATE DATABASE command: CREATE DATABASE dbName ON ( NAME = dbName_dat, FILENAME = 'D:\path\to\dbName.mdf' ) LOG ON ( NAME = dbName_log, FILENAME = 'D:\path\to\dbName.ldf' ) As you can see from the linked article, you can

I need best practice in T-SQL Export data to CSV (with header)

自闭症网瘾萝莉.ら 提交于 2019-11-30 05:48:32
问题 What I need to do is export data into CSV file using T-SQL. And I'm very confused about there are many ways can do it, I don't know to choose which one, please help me to confirm the bollowing: As I know there are about 3 methods, and I want you help me to confirm: Using Microsoft.Jet.OLEDB.4.0, like this: INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Text;Database=C:\Temp\;HDR=Yes;', 'SELECT * FROM test.csv') (object_id, name) SELECT object_id, name FROM sys.tables; but this need the

Run sqlcmd without having SQL Server installed

吃可爱长大的小学妹 提交于 2019-11-30 03:20:00
I'm working on a Java program that is calling sqlcmd . It works perfectly on a computer with SQL server installed, but not at all on a computer that doesn't. I want to include the necessary exe and dll files to run this command in my jar. Anyone know which ones I need? I already included batchparser90.dll, sqlcmd.exe, and sqlcmd.dll. It still didn't work. Any suggestions are appreciated. Thanks in advance! Although it's probably too late for the original poster, for future reference, SQLCMD is freely downloadable, so it's not necessary to purchase SQL Server explicitly for this purpose.

How to connect Sqlcmd to the server?

谁都会走 提交于 2019-11-30 02:50:21
I just installed SQL Server 2008, and I wanted to use the command editor to execute queries. To do that I opened the command prompt, and I typed Sqlcmd -S Serverinstance but I got an error saying : Named Pipes Provider: Could not open a connection to SQL Server [53]. Sqlcmd : erreur : Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL

How do I call a stored procedure with arguments using sqlcmd.exe?

折月煮酒 提交于 2019-11-30 01:25:48
问题 I need to call a stored procedure and pass arguments in from Powershell. I think the best option is to use sqlcmd.exe but I'm not sure how to pass arguments to the stored proc using this tool. 回答1: sqlcmd.exe supports variable substitution and parameters via the /v argument, see Using sqlcmd with Scripting Variables. For example: sqlcmd -E -d <mydb> -Q "exec usp_myproc @variable=$(myparam)" /v myparam=1 will invoke the procedure passing the value 1 to the script to be substituted for the

How to use sqlcmd to create a database

浪子不回头ぞ 提交于 2019-11-29 17:38:57
问题 I have a .sql script and I want to build a database from it. How to do it in sqlcmd? I know it's like: CREATE DATABASE dbName GO But how to specify the .sql script and location to build the database? 回答1: Use @Jeremiah Peschka's answer to supply the sqlcmd utility with the script to execute. As for the location for the newly created database, it can be specified as part of the CREATE DATABASE command: CREATE DATABASE dbName ON ( NAME = dbName_dat, FILENAME = 'D:\path\to\dbName.mdf' ) LOG ON (

SQL Server Network Interfaces: Connection string is not valid [87]

*爱你&永不变心* 提交于 2019-11-29 10:37:32
When I am running this from cmd on my SQL Server 2008 instance: sqlcmd -U sa -S mymachinen_name\MSSQLSERVER (where MSSQLSERVER is my instance name) I get prompt for password and after that I get this: Password: HResult 0x57, Level 16, State 1 SQL Server Network Interfaces: Connection string is not valid [87]. Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote

ServerConnection.ExecuteNonQuery in SQLCMD Mode

我是研究僧i 提交于 2019-11-29 07:55:36
问题 I am using the Microsoft Data-Tier Application framework to create a deployment script based on a DacPackage object. I am attempting to use the Microsoft.SqlServer.Management.Smo.Server class to execute this script... SqlConnection deployConnection = new SqlConnection(connBuilder.ToString()); deployConnection.Open(); Server server = new Server(new ServerConnection(deployConnection)); server.ConnectionContext.ExecuteNonQuery(deployScript); However, this errors out with... Unhandled Exception:

How to execute sqlcmd from powershell?

六眼飞鱼酱① 提交于 2019-11-29 06:01:43
问题 I have a string in powershell, which contains a native sqlcmd command. The command itself can be executed successfully in cmd.exe. I have difficulty in executing them in powershell. Anyone can help? Thanks. This is sql.sql select @@servername go select @@servicename This is the result when I execute the sqlcmd command from cmd.exe C:\Users\test>sqlcmd -S "(local)\instance1" -U a -P a -i "c:\temp\sql.sql" -------------------------------------------------- thesimpsons\INSTANCE1 (1 rows affected

How to connect Sqlcmd to the server?

跟風遠走 提交于 2019-11-29 00:30:38
问题 I just installed SQL Server 2008, and I wanted to use the command editor to execute queries. To do that I opened the command prompt, and I typed Sqlcmd -S Serverinstance but I got an error saying : Named Pipes Provider: Could not open a connection to SQL Server [53]. Sqlcmd : erreur : Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is