Insert Varbinary Data Using Command-line Sqlcmd

May 23, 2008



Hi,

I have a SQL script file which creates a table and and inserts all data required by the client app into the table.

The table also holds images in a varbinary field. How do I insert an image held on the file system (e.g. "C:ImagesMyImage.gif") into a varbinary field using a script that is run using sqlcmd on the command line?


Any pointers greatly appreciated!

Mike

View 8 Replies


ADVERTISEMENT

SQLCMD - How Do I Pass Parameter At Dos Command Line To Input File?

Mar 23, 2007

I am not sure if this has been asked before but I couldn't find any thread talking about this.

Let's say we have a parameter in the .sql input file called @Start_Date, how can we pass the value of a particular date, for example, "02-28-2007" to @Start_Date via SQLCMD? is it possible?

I'm trying to skip the need to write a simple windows application...if things can be achieved via dos command line, that will keep everything simple!

thanks! :)

View 3 Replies View Related

Command Line And Insert

Sep 22, 2005

I'm trying to insert into a table 2 values one of which is an

exec master..xp_cmdshell @command where I have assigned @command with a value

this statement gives me the result into a 1 col. table fine:

insert into mytable99(col1) exec master..xp_cmdshell @command

now what I want to do is put col2 in there as well!!

ie. insert into mytable99(col1,col2) values (exec master..xp_cmdshell @command, '123')

I get a sytax error ... on the exec ??

Could anyone help re the proper way of doing this ... thanks in advance

View 1 Replies View Related

MS SQL Command Line Insert

Oct 13, 2005

I use a similar command below to insert into a temp table the result of a large command line call to an exectable with many parameters passed in the command of which the result passed back contains many items. I then parse the response string to get my results...

set @command = 'dir'
insert into tsverisign(response) exec master..xp_cmdshell @command


My question is our can I insert two values at the same time to this same table one of which is my "exec master..xp_cmdshell @command"

similar to insert into tables (field_a, feild_b) values ('1','2')

Something like (and I know this does not work):

insert into tsverisign(response,trans_id)
values (exec master..xp_cmdshell @command, '123')

Any help would be greatly appreciated .... PS I'm new to MS SQL 2000 and proper syntax etc. etc. so I need full example so I can try. :rolleyes:

View 1 Replies View Related

SQL Server Compact 3.5 - I've A Sdf File Created In A .NET Windows Desktop Command Line Program. How To Now Consume The Data?

Sep 17, 2007



SQL Server Compact 3.5 - I've a sdf file created in a .NET windows desktop command line program. How to now consume the data in MS Excel?

I can see that under

C:Program FilesMicrosoft SQL Server Compact Editionv3.5

I've one DLL called


sqlceoledb35.dll

But I don't have any oledb driver listed when creating an UDL file?

How can I consume the data in other apps that are not .NET and developed in house them?


Thanks, AM.

View 13 Replies View Related

Insert Command Fails When I Want To Insert Records In Data Table

Apr 20, 2008

On my site users can register using ASP Membership Create user Wizard control.
I am also using the wizard control to design a simple question and answer  form that logged in users have access to.
it has 2 questions including a text box for Q1 and  dropdown list for Q2.
I have a table in my database called "Players" which has 3 Columns
UserId Primary Key of type Unique Identifyer
PlayerName Type String
PlayerGenre Type Sting
 
On completing the wizard and clicking the finish button, I want the data to be inserted into the SQl express Players table.
I am having problems getting this to work and keep getting exceptions.
 Be very helpful if somebody could check the code and advise where the problem is??
 
 
<asp:Wizard ID="Wizard1" runat="server" BackColor="#F7F6F3"
BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px"
DisplaySideBar="False" Font-Names="Verdana" Font-Size="0.8em" Height="354px"
onfinishbuttonclick="Wizard1_FinishButtonClick" Width="631px">
<SideBarTemplate>
<asp:DataList ID="SideBarList" runat="server">
<ItemTemplate>
<asp:LinkButton ID="SideBarButton" runat="server" BorderWidth="0px"
Font-Names="Verdana" ForeColor="White"></asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle Font-Bold="True" />
</asp:DataList>
</SideBarTemplate>
<StepStyle BackColor="#669999" BorderWidth="0px" ForeColor="#5D7B9D" />
<NavigationStyle VerticalAlign="Top" />
<WizardSteps>
<asp:WizardStep runat="server">
<table class="style1">
<tr>
<td class="style4">
A<span class="style6">Player Name</span></td>
<td class="style3">
<asp:TextBox ID="PlayerName" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="PlayerName" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style5">
 
<td class="style3">
<asp:DropDownList ID="PlayerGenre" runat="server" Width="128px">
<asp:ListItem Value="-1">Select Genre</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="PlayerGenre" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
</td>
 
</tr>
</table>
  Sql Data Source
<asp:SqlDataSource ID="InsertArtist1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" InsertCommand="INSERT INTO [Playerst] ([UserId], [PlayerName], [PlayerGenre]) VALUES (@UserId, @PlayerName, @PlayerGenre)"
 
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>">
<InsertParameters>
<asp:Parameter Name="UserId" Type="Object" />
<asp:Parameter Name="PlayerName" Type="String" />
<asp:Parameter Name="PlayerGenre" Type="String" />
</InsertParameters>
 
 
</asp:SqlDataSource>
</asp:WizardStep>
 
 Event Handler
 
To match the answers to the user I get the UserId and insert this into the database to.protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
 SqlDataSource DataSource = (SqlDataSource)Wizard1.FindControl("InsertArtist1");
MembershipUser myUser = Membership.GetUser(this.User.Identity.Name);
Guid UserId = (Guid)myUser.ProviderUserKey;String Gender = ((DropDownList)Wizard1.FindControl("PlayerGenre")).SelectedValue;
DataSource.InsertParameters.Add("UserId", UserId.ToString());DataSource.InsertParameters.Add("PlayerGenre", Gender.ToString());
DataSource.Insert();
 
}
 

View 1 Replies View Related

SQLCMD Command Prompt Window Not Functioning Properly

Sep 15, 2007

The MSDN Library topic Using the sqlcmd utility(SQL Server Express) states "To access the sqlcmd utility, click Start, click Run, and type sqlcmd.exe."

A command prompt window opens with "SQLCMD" in the title bar. I cannot enter anything in the command prompt window and the window remains open for only about five or six seconds.

The version I have installed is MS SQL Server 2005 Express with SP2. The cumulative updates package 3 does not list this problem, so I did not install it.

View 1 Replies View Related

SQLCMD Gives Crazy Output From A Simple SELECT Command

Sep 25, 2006

Hi everyone,

I am new to T-SQL and am trying to do some simple database for fun. Here is my problem and hope you guys can drop me some hint or solution:

OS: Win XP pro
SQL Server 2005 Express
Tool: SQLCMD in command prompt

I created a database and then create a table. Then I tried : select * from contract_Info, it gave me this:

1> CREATE TABLE Contract_Info
2> (
3> Order_No varchar(50) NOT NULL ,
4> Company varchar(255),
5> Product_Name varchar(255) NOT NULL,
6> Discount_Rate varchar(50), --Discount_Rate (%) -> Discount_Rate
7> Status varchar(50) NOT NULL,
8> Quantity varchar(50) NOT NULL,
9> Remainder varchar(50),
10> Deleted bit
11> )
12>
14>
15>
16> INSERT INTO Contract_Info values ('00000', 'DEFAULT','DEFAULT','0','Cancelle
d','0','0',0)
17>
18> go

(1 rows affected)
1> select * from contract_Info
2> go
Order_No Company


Product_Name



Discount_Rate Status
Quantity Rema
inder Deleted
-------------------------------------------------- -----------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------------------------ -------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- -------------------------------------------------- --------------------------
------------------------ -------------------------------------------------- ----
---------------------------------------------- -------
00000 DEFAULT


DEFAULT



0 Cancelled
0 0
0

(1 rows affected)
1>





In SQL Express Management , the output looks perfectly fine

What is missing??

Thanks for your time

View 6 Replies View Related

How To Use Sqlcmd Command To Login To Sqlserver With Sa Account Which Have Empty Password

Oct 11, 2007

the password of sa account is empt

I use "sqlcmd -S servername -U sa " command but failed

any suggestions?

thanks

View 8 Replies View Related

Sqlcmd On SQL EXPRESS: Access Denied During CREATE DATABASE Command

Apr 24, 2007



Scenario:

I have installed SQL Express 2005 and I want to create a new DB using sqlcmd.



I am running a command like: sqlcmd -i file.ini (I am logged like Administrator of PC)

the content of the file.ini is:



-- Get the SQL Server data path
DECLARE @data_path nvarchar(256);

SET @data_path = 'c:Program FilesMyTestdatabase'



-- execute the CREATE DATABASE statement
EXECUTE ('CREATE DATABASE DataCollection ON
( NAME = DC_dat,
FILENAME = '''+ @data_path + 'DC.mdf'',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = DC_log,
FILENAME = '''+ @data_path + 'DClog.ldf'',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB )'
) ;
GO



I obtain this error:

Msg 1802, Level 16, State 4, Server TESTQ5SQLEXPRESS, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Msg 5123, Level 16, State 1, Server TESTQ5SQLEXPRESS, Line 1
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'c:Program FilesMyTestdatabaseDC.mdf'.


If I change the security of directory database (I add "modify" permission to Users windows group) the error disappear.

I am logged like Administrator... why is it necessary to change directory permission?



View 9 Replies View Related

Skip The First Line Of The Data File - Bulk Insert

Oct 1, 2007

Hi,
I have a data file and the contents of it are as follows

2 -- This is the header indicating the no of records in my files
1001|s1
1006|s2

The content of format file is as follows. This is to skip first column of the all the rows and get only Subs (i.e s1 and s2 )


9.0

2
1 SQLCHAR 0 100 "|" 0 ID ""

2 SQLCHAR 0 100 "
" 1 Subs ""


Here is my query to get all the Subs from my data file


SELECT * FROM OPENROWSET( BULK 'datafile.txt',

FORMATFILE = 'FormatFile.fmt',

FIRSTROW = 2 ) AS a

But this query retuns only s2 where i was expeting s1 and s2. The reason being is that the firts row i.e header doesn't follow the format
Can any one please let me know how to skip the first line in the data file and get the result as required

~Mohan

View 6 Replies View Related

Data Lost After INSERT Command

Dec 21, 2006

I have a website that is used to enter dates from a calendar. For example, user A might go to the website and select 20 different days in January. When user A clicks on the Save button the dates are written to the database with an INSERT command. This works fine. However, when user B then goes through the same procedure, say selecting 5 dates that are in the set selected by user A, those dates are properly saved in the database but the rows containing user A's same 5 dates disappear. I suspect this is something simple but I'm new and ignorant. Please help.

View 4 Replies View Related

How To Write Command For Insert Data With Running Number

Jan 11, 2008

My table has a running number primary key. I want to insert data to this table and automatically generate running number pk. I try to write SQL command like this.
SELECT MAX(ID) AS MaxId from test
INSERT INTO test (ID, data1, data2, data3) VALUES (MaxId+1, @data1, @data2, @data3)
but it fails. How should I do? Thank you in advance

View 1 Replies View Related

Insert Null Value Into Varbinary(max) Column

Apr 20, 2008

Hello,  
I'm working on a website that allows users to upload small JPEG files. I followed the article at http://aspnet.4guysfromrolla.com/articles/120606-1.aspx. On the webpage I'm using a formview control to insert new records in the database. As suggested in the article I removed the "type='object'" from the insert parameters for the image column. The data is saved by using a sqldatasource with stored procedures. The image column is of type varbinary(max) and allows null values. Everythings works fine as long as the user uploads an image. The data is saved correctly and on another page the image can be viewed. However if the user does not upload a picture and tries to save the new record the following error is thrown: 
�Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.�
 In the formviews iteminserting event I have the following code: Dim imageBytes(fileupload1.PostedFile.InputStream.Length) As Byte            fileupload1.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length)            e.Values("Image") = imageBytes What code should I use in case the fileupload1 has no file?  I tried something like:                        e.values("Image") = dbnull.value  But that doesn't work.  Any suggestions?  

 
 
 

View 5 Replies View Related

Command Line

Jul 23, 2005

Using Query Analyzer, I can right click on an object and select "scriptobject to new window as create" and I get the text of the object'sdefinition (schema). Can I get same result from command line, i.e., fromosql, I can get text output for the definition of the object (something likedefncopy under Sybase)? If so, what is the command or store procedure name?Thanks in advance.

View 2 Replies View Related

Command Line For SQL?

Apr 2, 2008

Is there any command line that I can use to do select from databases (SQL 2005)

View 4 Replies View Related

Defining Command,commandtype And Connectionstring For SELECT Command Is Not Similar To INSERT And UPDATE

Feb 23, 2007

i am using visual web developer 2005 and SQL 2005 with VB as the code behindi am using INSERT command like this        Dim test As New SqlDataSource()        test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToString()        test.InsertCommandType = SqlDataSourceCommandType.Text        test.InsertCommand = "INSERT INTO try (roll,name, age, email) VALUES (@roll,@name, @age, @email) "                  test.InsertParameters.Add("roll", TextBox1.Text)        test.InsertParameters.Add("name", TextBox2.Text)        test.InsertParameters.Add("age", TextBox3.Text)        test.InsertParameters.Add("email", TextBox4.Text)        test.Insert() i am using UPDATE command like this        Dim test As New SqlDataSource()        test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ToString()        test.UpdateCommandType = SqlDataSourceCommandType.Text        test.UpdateCommand = "UPDATE try SET name = '" + myname + "' , age = '" + myage + "' , email = '" + myemail + "' WHERE roll                                                         123 "        test.Update()but i have to use the SELECT command like this which is completely different from INSERT and  UPDATE commands   Dim tblData As New Data.DataTable()         Dim conn As New Data.SqlClient.SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated                                                                                Security=True;User Instance=True")   Dim Command As New Data.SqlClient.SqlCommand("SELECT * FROM try WHERE age = '100' ", conn)   Dim da As New Data.SqlClient.SqlDataAdapter(Command)   da.Fill(tblData)   conn.Close()                   TextBox4.Text = tblData.Rows(1).Item("name").ToString()        TextBox5.Text = tblData.Rows(1).Item("age").ToString()        TextBox6.Text = tblData.Rows(1).Item("email").ToString()       for INSERT and UPDATE commands defining the command,commandtype and connectionstring is samebut for the SELECT command it is completely different. why ?can i define the command,commandtype and connectionstring for SELECT command similar to INSERT and UPDATE ?if its possible how to do ?please help me

View 2 Replies View Related

Automating Ftp Command Line

May 1, 2001

hi I would appreciate if someone demonstrate how to automate ftp in a command line from within a batch file. I do want to move certain files from one server to another via ftp command line in an automatic fashion via running the batch periodically.

thanks

Ali

View 1 Replies View Related

URGENT: Can&#39;t Run BCP Via Command Line

Jun 13, 2000

hi: I can't seem to run BCP thru the command line.

bcp pubs..authors out c:authors.txt -c -Usa -P

error:
Msg 170, Level 15, State 1, Server Y47SA, Procedure , Line 1
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near'.'.

I've been trying to run BCP thru command line all day. I tried OSQL, ISQL. I find this utility very
frustrating. btw - I have installed SP2.

any thoughts would be much appreciated.
TIA
deanna

View 5 Replies View Related

Command Line Tools

Sep 25, 2002

Anyone know where I can find some command line tools such as RCMD etc.. Thank you.;)

View 1 Replies View Related

Creating DB Using Command Line

Jun 11, 2007

Hi All,

I was given a task of coming up with the script to recreate an existing database using a command line. I would use this script in case when the server is down and I can't get to Query Analyzer or EM to recreate it. I am not sure where to start. Any ideas are greatly appreciated.

Thanks.

View 5 Replies View Related

DB Backup From Command Line ?

May 21, 2004

What ius the synthax to backup an SQLServer DB from the command line ?

Thanks

View 1 Replies View Related

Restart SQL Using Command Line

Jan 29, 2008

Can someone give me the command to restart SQL?

Thanks

View 1 Replies View Related

Restore From Command Line

Jul 23, 2005

I want to restore a backup copy of a database from the command line. Canthis be done?Thanks, Tom.

View 2 Replies View Related

Is Any Possible To Run DTS Package From Command Line ?

Jul 20, 2005

Hi Sir:Is any possible to run DTS package from Command Line ?Lucas

View 1 Replies View Related

Command Line Install

May 4, 2007

I am trying to create an quiet install for SQL Server Express. The install is being run under a local administrators account. However, when a user, who is only in the local users group, accesses the application using ClickOnce deplolyment, it says SQL Server Express Edition is not installed.



-Dan

View 1 Replies View Related

How To Set SQL Profiler Via Command Line

Mar 14, 2007

Hello,

How can I set SQL Profiler to capture the logs via command line?

This is what I have:

I already have a SQL Profiler Template (fooTemplate.tdf) which tells what I need SQL to capture.

C:>"C:Program FilesMicrosoft SQL Server90ToolsBinnPROFILER90.EXE" /Sfoo /Dfoo /E /T"c:fooTemplate.tdf" /Oc:mysql.out

What other parameters am I missing?

Thanks!

J

View 3 Replies View Related

COMMAND LINE PARAMETERS

Apr 22, 2008

Hi all,

A quick newbie question...

I am trying to install SQL Server 2005 Standard and upgrade from Express edition. The Edition Change check tells me I must run the setup from the command prompt "and include the SKUUPGRADE=1 parameter", but I don't know how to enter this from the command line.

I've tried "D:setup SKUUPGRADE=1" and "D:setup -SKUUPGRADE=1", as well as "D:setup.exe /SKUUPGRADE=1" without success.

Can anyone give me a clue as to where I'm going wrong?

Thanks in advance.

Slammin!

View 3 Replies View Related

Can't Set Variable Through Command Line

Mar 29, 2007

Hello everyone!

Bit of a problem executing a DTS command from a command line.

I have the following variables defined in my package:

UserVarchar1
UserVarchar2
UserVarchar3

All have a scope of Package, all of the mstrings

The command I'm attempting to run in 1 line is:

DTEXEC /FILE "C:SSIS PackagesED-CustomersPackage.dtsx"
/SET Package.Variables[User::UserVarchar1].value;"10"
/SET Package.Variables[User::UserVarchar2].value;"30719"
/SET Package.Variables[User::UserVarchar3].value;"BILLTO"




Description: The package path referenced an object that cannot be found: "Package.Variables[User::UserVarchar1].value". This occurs when an attempt is made to resolve a package path to an object that cannot be found.


DTExec: Could not set Package.Variables[User::UserVarchar1].value value to 10.

Any idea why?

Thanks for the help!

View 10 Replies View Related

SQL 7 Restore From Command Line (URGENT)

Jul 10, 2002

Hey Folks,

I have inherited a project from a co-worker who has had a family tradegy, and I am trying to get up to speed with her project.

We have an SQL server 7 database which is getting backed up every night (by SQL itself) into a .BAK file. I need to know if it is possible to restore this file from the command line (a DOS prompt.) I know (or think I know) how to do it from within SQL Enterprise Manager, however the specific needs of this project require it be done from a command line on the machine.

I really am not an SQL guru...I don't even think I qualify as "knowing what I am doing" at all, so any advice you can offer will be greatly appreciated. This is kind og urgent, so your thoughts are welcome!

Thanks!

Mike

View 1 Replies View Related

Isql Command Line Arguments

Jun 26, 2000

Does any know of a technique to filter out headers dashes and row count in an output file of an isql result? These switches seem to be available when running as isql/w, but not the command line. The -h-1 argument for no headers had no effect. Thanks in advance. Ron Hurley

View 1 Replies View Related

Starting SQLServer From Command Line

May 5, 2000

Does anyone know how to start sqlserver 7.0 from command line for windows 98?


Thanks

View 1 Replies View Related

RCMD Command Line Util.

Oct 31, 2002

I'm trying to use the rcmd utility and when i try to connect to a server with it i get this error...

system not found or service not active? How do you activate the rcmd service? thanks for your help.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved