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?
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!
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:
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??
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();
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.
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?
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
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.
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
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?
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.
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
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.
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.
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.
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?
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.
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!
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