How To Insert Binary To SQL Express By VBA?

Oct 4, 2007

Hi all,

In the end of the post, there is my vba functions and query to create datatable. I got a run-time error message on the red line in the function. It says: [sql native client] string data right truncation. Did I do sometime wrong? Thanks for your time!

-L

Sub test()
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
Dim mConn As ADODB.Connection
'read the file data to bytes
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile file
Dim mCmd As ADODB.Command
Set mCmd = New ADODB.Command
With mCmd
' define query
.CommandText = "INSERT INTO TEST (FDATA) " & _
"VALUES (?)"
.CommandType = adCmdText
' add parameter
.Parameters.Append .CreateParameter("@P1", adVarBinary, _
adParamInput, BinaryStream.Size, BinaryStream.Read)
End With
' open db connection
mConn.ConnectionString = _
"Driver={SQL Native Client};Server=.SQLEXPRESS;Database=XXXX;Trusted_Connection=yes;"
mCmd.ActiveConnection = mConn
'run-time error: [sql native client] string data right truncation
mCmd.Execute
mConn.Close
End Sub



GO
/****** Object: Table [dbo].[TEST] Script Date: 10/04/2007 11:06:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TEST](
[ID] [int] IDENTITY(1,1) NOT NULL,
[FDATA] [varbinary](max) NOT NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

View 3 Replies


ADVERTISEMENT

Insert Binary Data

Jan 4, 2008

Hi my first post so be gentle :D

I have a table which has a column of type binary(200)

I want to put some test data into this table just using sql server managment studio express

how do i do this i keep getting message which says

"the changed value in this cell was not recognized as valid .NET framework data type: Byte[]"

Thanks,

Adam

View 1 Replies View Related

Can't Insert Binary Data Into Sql Mobile

Jul 9, 2006

Hi guys, I'm having a problem inserting a file into a SQL Mobile table.

I'm updating the table via a tableadapter designed through the Dataset designer in VS2k5.

The SQL used to insert is "Insert into TestTable (itemid,itemdata) values (@itemid,@itemdata)"

Where ItemID is a GUID, and ItemData is an Image field. The tableadapter has typed the parameters as GUID and Binary properly already.

Only problem is when I actually call the command with a byte array containing my file, I get a "Byte truncation" error message.

I remember this working properly in SQL CE 2.0 but so far I don't seem to get it to work in SQL mobile, anyone got any pointers?

View 3 Replies View Related

Storing Binary Files In SQL Express

Nov 29, 2006

Hi There,

I am new to VC# and SQL Express. I am currently trying to find a way to store user selected files into SQL Express. I am using a column with the varbinary(MAX) data type. My current thought is to give the user a open file dialog box, and let them select the file they want to upload. On closing this dialog box, I convert the file selected into a file stream and insert into SQL Express.

Is this method a good one? If anyone else can give me pointers or hints to better methods, please do!

Thanks,
Ke

View 4 Replies View Related

Binary Data Insert Fails Using Dblib

Jul 30, 2004

who still uses the old dblib can help me?
thanks in advance:


1.create table & procedure in db:
test_table(uniqueidentifier a,varbinary50 b)
CREATE PROCEDURE insert_table
@b_in varbinary
AS
insert into test_table(b) values (@b_in)
GO

2.write program use dblib:
wchar_t str[120]=L"ABC";
dbrpcparam(dbproc[i], "@b_in", (BYTE)NULL, SQLVARBINARY,
-1, 6, &str)

3.I can find the program executed successfully,but only 1 Byte is inserted:
a b
-----------------------------------------------
199D71BE-327A-4BC1-AEC8-ACB0C96076CA 0x41



how to insert the whole string into the database?

View 2 Replies View Related

Insert Error :String Or Binary Data Would Be Truncated.

Feb 13, 2001

Hi, got this sql statement, I am not sure why I am getting this error message at the botton. Thanks for your input:

insert into generator(member_id,contact_id,company_name,contac t_fname)
select member_id,contact_id,company_name,contact_fname
from customer

Server: Msg 8152, Level 16, State 9, Line 1
String or binary data would be truncated.
The statement has been terminated.

Thanks

View 1 Replies View Related

Concatenate All Binary Columns Into Single Binary Column?

May 22, 2014

Server is SQL 2000

I have a table with 10 rows with a varbinary column

I wish to concatenate all the binary column into a single binary column and then write that to another table within the database. This application splits a binary file (Word or PDF document) into multiple segments (this is Column2 as below)

example as follows

TableA

Column1 Column2 Column3
aaa 001 <some binary value>
aaa 002 <some binary value>
aaa 003 <some binary value>
aaa 004 <some binary value>
aaa 005 <some binary value>

desired results in TableB

Column1 Column2
aaa <concatenated value of above binary columns>

View 9 Replies View Related

T-SQL (SS2K8) :: Store Binary Data Rather Than Int Or Binary?

May 7, 2015

I'm using a bit-wise comparison to effectively store multiple values in one column. However once the number of values increases it starts to become too big for a int data type.you also cannot perform a bitwise & on two binary datatypes. Is there a better way to store the binary data rather than int or binary?

View 9 Replies View Related

String Or Binary Data Would Be Truncated. I Get This Error When Entering Data Using Sql Server Management Studio Express.

May 21, 2008

String or binary data would be truncated. I get this error when entering data using sql server management studio express.

I am not running a sql to insert or update the table. This is through the EDI.

The data type is varchar(100). I enter one character and it errors on me. So this isn't a string being too long problem.

Any ideas?



View 2 Replies View Related

Data Insert Via SQL Express Using VB Issue

Jun 27, 2006

I've been doing a lot of research lately to determine the most secure way to issue an insert statement to insert my data into my SQL database.  I'm coding this following using Visual Basic: Protected Sub submitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim strConn As String = "server=.SQLEXPRESS;database=C:SJ-siteSJApp_DataSJDb.mdf; User Id=user; password=password"
Dim MyQuery As String = "Insert into sjTable (PostID, Category, TitleofPost, Description, Price, Loc, ContactInfo, DatePosted, Disclaimer) Values (@Category, @TitleofPost, @Description, @Price, @Loc, @ContactInfo, @DatePosted)"
Dim MyConn As New Data.SqlClient.SqlConnection(strConn)
Dim cmd As New Data.SqlClient.SqlCommand(MyQuery, MyConn)
Dim curDate As String
On Error Resume Next

MyConn.Open()
If Err.Number <> 0 Then
MsgBox("There was an error connecting to the database.", MsgBoxStyle.OkOnly)
Err.Number = 0
End If

curDate = Now()
With cmd.Parameters
.Add(New System.Data.SqlClient.SqlParameter("@Category", categoryDropDown.Text))
.Add(New System.Data.SqlClient.SqlParameter("@TiteofPost", titleTextbox.Text))
.Add(New System.Data.SqlClient.SqlParameter("@Description", descriptionTextbox.Text))
.Add(New System.Data.SqlClient.SqlParameter("@Price", priceTextbox.Text))
.Add(New System.Data.SqlClient.SqlParameter("@Loc", locationTextbox.Text))
.Add(New System.Data.SqlClient.SqlParameter("@ContactInfo", contactTextbox.Text))
.Add(New System.Data.SqlClient.SqlParameter("@DatePosted", curDate))
End With
If Err.Number <> 0 Then
MsgBox("There was an error inserting the data into the database.", MsgBoxStyle.OkOnly)
Err.Number = 0
End If

MyConn.Close()
If Err.Number <> 0 Then
MsgBox("There was an erro closing the database connection.", MsgBoxStyle.OkOnly)
Err.Number = 0
End If
Server.Transfer("submitted.aspx")


End Sub The code gives no errors, it directs me straight to the
submitted.aspx page but when I query the database it is not inserting
any data into my database.  .My Error log shows the following:2006-06-27 12:14:16.68 spid51      Starting up database 'C:SJ-SITESJAPP_DATASJDB.MDF'.2006-06-27 12:14:26.93 Logon       Error: 17828, Severity: 20, State: 3.2006-06-27 12:14:26.93 Logon       The prelogin packet used to open the connection is structurally invalid; the connection has been closed. Please contact the vendor of the client library. [CLIENT: <local machine>]I am able to log into the database using my account via SQL Server Management Studio Express.  I've been all over the forums and google looking for a solution but everything I've been trying to mock up from other people's code hasn't helped.  Thanks in advance for your assistance

View 3 Replies View Related

SQL Express 2005 Insert Command

Aug 30, 2006

I have the following insert parameter and insert command which are attached to a templated textbox, I have made the textbox's visible property false so the user will not enter any text. I have a session variable session("test") = 500. I would like the value of the session variable to be inserted into the testcode field. I can not seem to find any workable syntax.<InsertParameters> <asp:Parameter Name="TestlCode" Type="Int32" />InsertCommand="INSERT INTO [Mycd] ( [TestlCode], ..   VALUES ( @testcode ,

View 1 Replies View Related

SQL Server Express Bulk Insert

Oct 25, 2006

does anyone know how to do a bulk insert in SQL Server Express thanks Marcel

View 2 Replies View Related

SQL Express 'hangs' When Executing An INSERT

Feb 14, 2008

Periodically an INSERT query takes anywhere from 30 to 90 sec's to execute. But once it completes, execution times then return to 0 or 1 sec. This has begun to occur more and more frequently, typically every thirty minutes or so now.
The only way I have found to clear the problem is to execute the INSERT from SQL Studio and just wait for it to complete. Then everything returns to normal, until it hangs again. The application that commands the INSERT can not be made to just wait for 90 seconds, so I need to know how to eliminate the intermittent delay.
What could be causing this problem, and how can it be corrected?

View 5 Replies View Related

Faulty Insert Into Sql Express Database

Apr 2, 2007

Hello All,

I have an InfoPath form that submits data to a .NET webservice. The webservice parses the infopath form and inserts the data into a database. The database is SQL Server EXPRESS.

I have however run into some problems. The InfoPath form is within SharePoint and I noticed that when I submit the data, it only shows up in the database as a new record 9 out of 10 times. That is for every 10 submissions of the form, there are only about 9 new records in the database. The ID field (an autoincrement field) also skips a number indicating the the transaction may have failed.

However, when I test the form on my local PC, it inserts a new record for every submission.

The webservice and database are on a remote server not my local.

Does anyone have any ideas? Could it be a deficiency of SQL Server Express?

Any ideas, answers or suggestions would be much appreciated.

View 1 Replies View Related

Insert Data Into SQL SERVER EXPRESS Edition

Apr 20, 2007

I'm completely new to ASP.NET. I want to insert data to the SQL SERVER EXPRESS database.When the button clicks i want to add the details into database.This is the coding i did with online help.
Can you help me to do a good coding ad some error showing on my 7th line("connection.Open()")..
And can you advise me to do correct coding for how is get data from database and display it on web page.
Thanks in advance.And here is the coding i did to Insert data,
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connection As New SqlConnection(" database=share")
Dim cmd As New SqlCommand("INSERT INTO sdetails (cid, cname, date, qty, pps)VALUES('" & txtcid.Text & "','" & txtcname.Text & "','" & txtdate.Text & "','" & txtqty.Text & "','" & txtpps.Text & "')", connection)
 
connection.Open()
connection.Close()
End Sub

View 2 Replies View Related

Insert Command In Sql Server Express Edition Using ASP.net C# Lan

Dec 31, 2007

Hi,
 i'm creating registeration form using VS2005, i want to insert values in sql server express 2005. i've coded but it is giving error plz hava a look
 for example my database name is Database1 and table is table1
and columns are name,title. 
here i'm getting error : connectionstring does not exist. 
 
code as folllows
SqlConnection connection = new SqlConnection(ConnectionString1);      
        string cmdString = "Insert into Table1(name,title)VALUES( @Name,@title)";
        SqlCommand cmd = new SqlCommand(cmdString, connection);
        cmd.Parameters.Add(new SqlParameter("@name",txtNameText));          cmd.Parameters.Add(new SqlParameter("@title",txtTitle.Text) );                        connection.Open();        cmd.ExecuteNonQuery();        connection.Close();
 
thanks in advance

View 6 Replies View Related

Insert Data To MsSQL Express Database?

Jan 4, 2008

Hello there,I'm to asp.net, so please be patient :DMy question is, how do I simply add some data to my database? - With vb.net code, not a grid view or something like that..I want to connect to my database, insert some data to a table.It shouldn't be that hard?- Hope someone will take the 5 minutes, and help me :)Regards Jeppe

View 16 Replies View Related

Insert Record Into Sql Database Express When Button Pressed

Apr 30, 2008

I'm new to asp.net and I have gotten quite far with books and such but I'm stuck at this point. I have a web form that is mostly populated with data pulled from AD and all the user does is make a selection in two drop lists and enter their initials to sign. I can't figure out how to insert a record into a table when buttin pressed. I verified that all the data types are correct so it shoud pass the info but its just not going anywhere. I've atached the code below.
Thanks,protected void accept_btn_Click(object sender, EventArgs e)
{
string adPath = LDAP://DC=********,DC=***; //Path to your LDAP directory servermembers adAuth = new members(adPath);
 string username = Context.User.Identity.Name;
string computer_name = System.Environment.MachineName;string comp_type = comptype.SelectedValue.ToString();
string install_type = installtype.SelectedValue.ToString();string date = DateTime.Now.ToString();
string email = adAuth.getemail(Context.User.Identity.Name);string agree = initials_txtbox.Text;string title = "Office";
 test_lbl.Text = (username + " " + computer_name + " " + comp_type + " " + install_type + " " + date + " " + email + " " + agree + " " + title);
 
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand();
System.Data.OleDb.OleDbParameter parameter1 = new System.Data.OleDb.OleDbParameter();System.Data.OleDb.OleDbParameter parameter2 = new System.Data.OleDb.OleDbParameter();
System.Data.OleDb.OleDbParameter parameter3 = new System.Data.OleDb.OleDbParameter();System.Data.OleDb.OleDbParameter parameter4 = new System.Data.OleDb.OleDbParameter();
System.Data.OleDb.OleDbParameter parameter5 = new System.Data.OleDb.OleDbParameter();System.Data.OleDb.OleDbParameter parameter6 = new System.Data.OleDb.OleDbParameter();
System.Data.OleDb.OleDbParameter parameter7 = new System.Data.OleDb.OleDbParameter();System.Data.OleDb.OleDbParameter parameter8 = new System.Data.OleDb.OleDbParameter();conn.ConnectionString = "provider=System.Data.SqlClient; Data Source=./SQLEXPRESS;AttachDbFilename=|DataDirectory|/software.mdf;Integrated Security=True;User Instance=True";
command.Connection = conn;
command.CommandText = "INSERT INTO [download_table] (username, computer_name, computer type, install type, date, email, agree, title) VALUES (?,?,?,?,?,?,?,?)";command.CommandType = CommandType.Text;
parameter1.ParameterName = "username";parameter1.DbType = DbType.String;
parameter1.Value = username;
command.Parameters.Add(parameter1);parameter2.ParameterName = "computer_name";parameter2.DbType = DbType.String;
parameter2.Value = computer_name;
command.Parameters.Add(parameter2);parameter3.ParameterName = "comptype";parameter3.DbType = DbType.String;
parameter3.Value = comp_type;
command.Parameters.Add(parameter3);parameter4.ParameterName = "installtype";parameter4.DbType = DbType.String;
parameter4.Value = install_type;
command.Parameters.Add(parameter4);parameter5.ParameterName = "date";parameter5.DbType = DbType.DateTime;
parameter5.Value = date;
command.Parameters.Add(parameter5);parameter6.ParameterName = "email";parameter6.DbType = DbType.String;
parameter6.Value = email;
command.Parameters.Add(parameter6);parameter7.ParameterName = "agree";parameter7.DbType = DbType.String;
parameter7.Value = agree;
command.Parameters.Add(parameter7);parameter8.ParameterName = "title";parameter8.DbType = DbType.String;
parameter8.Value = title;
command.Parameters.Add(parameter8);
try
{
conn.Open();
command.ExecuteNonQuery();
}catch (Exception ex)
{
}
finally
{
conn.Close();
}
}

View 3 Replies View Related

Not Able To Insert Record In SQL Server 2005 Express Edition

Jul 29, 2006

Hello,

In a web application of VS.Net 2005 I am able to insert records in both the database SQL 2000 & 2005

In a windows application of VS.Net 2005 I am able to insert record in SQl 2000 but I am not able to insert record in SQL 2005 Express Edition.

Please help Me I tried very Much but not succeded yet.

Thanks in Advance

View 6 Replies View Related

Sql 2005 Express: Cant Insert Records Due To Log File Being Full

Mar 27, 2008

im having an issue with sql server 2005 express on a test box. in recent testing, ive encountered errors with the database that i havent encountered before. im trying to use an app to add records to some tables in a database, 1 record at a time. but in doing so i get this



"The transaction log for database 'ScanOrder2' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases"





with every insert of a record.






this process was working fine 2 days ago and i cant find anything
thats been changed.
- i deleted the database and tried restoring it from a backup that is
known to work, but still has the issue
- the recovery model is set to simple. every night a batch script is
run to truncate the log file in case there is a transaction that uses
a lot of records
- i can insert and delete records manually with no problems (ie going
in through SSMSE and highlighting a row and deleting it or adding
random data) but i still cant add it through the app
- the log file is set to autogrow unrestricted at 10 megs at a time.
- i even tried setting the log file to 500 megs starting size, and
still couldnt even insert 1 record
- when i check the log_reuse_wait_desc, it says NOTHING, when not
running and while running.


is there any other setting i could be missing that might attribute to
this?

View 7 Replies View Related

Insert Arabic Text To Sql Express 2005 (windows Application)

Jul 17, 2007

Hi,

I need your help guys. Am devolving a windows application by c#. I have problem of insert Arabic text to sql express 2005. I always get ???? instead of the Arabic letters. I change the collation of the database field to windows collation and choose Arabic but still I get the same problem.

Your help is appreciated

View 7 Replies View Related

[SQL 2005 Express] How Do I Load Fixed Width Per Row Flat File? Bulk Insert Possible?

May 14, 2007

I can't use DTS nor DTSwizard as I need to put it in a .sql and run it through a command line via .bat file (it's more for the users).

Each row ends with an EOL character, the fields are all fixed width, but I have a little problem here, some rows are empty but just with a EOL character.

How shall I go about it?

many thanks! :D

View 2 Replies View Related

BULK INSERT Format File Problems With SQLNUMERICAL In SQL-Server 2005 Express

May 24, 2006

I'm trying to set up a BULK INSERT Format File for some data that I've been sent, which, according to the data documentation, comes in fixed-width format fields (no delimiters except for end-of-row 0D0A) in SQL-Server 2005 Express.

The following is the first line...
"7999163 09182003 56586 56477 3601942 1278 22139 1102 113 118 51450 1 1 63535647 10000
7999162 09182003 56586 56477 3601942 1279 22139 1102 113 118 51450 1 1 63535647 10000 "

Looking with a hex editor, all the above whitespace are 20's.

From the documentation, I've constructed the following table...

CREATE TABLE MQIC.DBO.ORDER_F
(
TRACER_ID NUMERIC (10,0),
DB_CREATE_DATE CHAR (8),
DB_UPDATED_DATE CHAR (8),
CREATE_DATE_KEY NUMERIC (10,0),
ORDER_DATE_KEY NUMERIC (10,0),
PATIENT_KEY NUMERIC (10,0),
ORDER_KEY NUMERIC (10,0),
PROVIDER_KEY NUMERIC (10,0),
LOCATION_KEY NUMERIC (10,0),
ORDER_TYPE_KEY NUMERIC (10,0),
STATUS_KEY NUMERIC (10,0),
PRIMARY_INSURANCE_KEY NUMERIC (10,0),
EXISTENCE NUMERIC (1,0),
DURATION NUMERIC (4,0),
NUMBER_OF_VISITS NUMERIC (3,0),
ACTIVITY_TRACER_ID NUMERIC (10,0),
AGE_KEY NUMERIC (10,0)
)

To Bulk Insert this, I've written the following...

BULK INSERT MQIC.DBO.ORDER_F
FROM 'E:MDataOrder_F.txt'
WITH
(
FORMATFILE = 'E:MDataOrder_F_format.txt'
)

and written the following format file...

9.0
17
1 SQLNUMERIC 0 10 "" 1 TRACER_ID ""
2 SQLCHAR 0 8 "" 2 DB_CREATE_DATE ""
3 SQLCHAR 0 8 "" 3 DB_UPDATED_DATE ""
4 SQLNUMERIC 0 10 "" 4 CREATE_DATE_KEY ""
5 SQLNUMERIC 0 10 "" 5 ORDER_DATE_KEY ""
6 SQLNUMERIC 0 10 "" 6 PATIENT_KEY ""
7 SQLNUMERIC 0 10 "" 7 ORDER_KEY ""
8 SQLNUMERIC 0 10 "" 8 PROVIDER_KEY ""
9 SQLNUMERIC 0 10 "" 9 LOCATION_KEY ""
10 SQLNUMERIC 0 10 "" 10 ORDER_TYPE_KEY ""
11 SQLNUMERIC 0 10 "" 11 STATUS_KEY ""
12 SQLNUMERIC 0 10 "" 12 PRIMARY_INSURANCE_KEY ""
13 SQLNUMERIC 0 1 "" 13 EXISTENCE ""
14 SQLNUMERIC 0 4 "" 14 DURATION ""
15 SQLNUMERIC 0 3 "" 15 NUMBER_OF_VISITS ""
16 SQLNUMERIC 0 10 "" 16 ACTIVITY_TRACER_ID ""
17 SQLNUMERIC 0 10 "
" 17 AGE_KEY ""

However... actually running this gives the following error...

Msg 4863, Level 16, State 4, Line 1
Bulk load data conversion error (truncation) for row 1, column 13 (EXISTENCE).
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".


Since this is my first time with this, I read the BOL items on Bulk Insert, Format Files, and each of the formatting attibutes, and made up two line "toy" examples for SQLCHAR and SQLINT, including two columns - all worked as expected.

It seemed that only SQLNUMERIC/SQLDECIMAL fell apart.

Even the following trivial example doesn't work for this field of data...

"7999163 "

CREATE TABLE MQIC.DBO.ORDER_F
(
TRACER_ID NUMERIC (10,0)
)

and

9.0
1
1 SQLNUMERIC 0 10 " " 1 TRACER_ID ""

or

9.0
1
1 SQLNUMERIC 0 10 "" 1 TRACER_ID ""

which give this error...


Msg 9803, Level 16, State 1, Line 1
Invalid data for type "numeric".
The statement has been terminated.

or

9.0
1
1 SQLNUMERIC 0 10 "/r/n" 1 TRACER_ID ""

which gives this error...

Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".


Also - there was the DB_CREATE_DATE and DB_UPDATED_DATE CHAR (8) were supposed to be dates in the format of mmddyyy but clearly there is no Date datatype in SQL-Server. I would suppose these need to be converted, but am unsure how. What is clear is that the data was dumped from Oracle in text form,

Any thoughts on this would be greatly appreciated...

Thanks!

View 1 Replies View Related

Shortcut To Insert New GUID Into Uniqueidentifier Cell In MSSQL Management Studio Express?

Jul 15, 2006

Hi,

anyone knows if there's an easy way to insert new GUIDs into uniqueidentifier cells when editing data in table on Management Studio Express? or Visual Studio 2005 Server Explorer? I can't find a shortcut, and copying from external tools is pain..

I suppose it's possible to build a VB macro in Visual Studio, would it work when editing table data?

Thanks in advance!

View 8 Replies View Related

BULK INSERT Format File Problems With SQLNUMERICAL In SQL-Server 2005 Express

May 24, 2006

I'm trying to set up a BULK INSERT Format File for some data that I've been sent, which, according to the data documentation, comes in fixed-width format fields (no delimiters except for end-of-row 0D0A) in SQL-Server 2005 Express.

The following is the first line...
"7999163 09182003 56586 56477 3601942 1278 22139 1102 113 118 51450 1 1 63535647 10000
7999162 09182003 56586 56477 3601942 1279 22139 1102 113 118 51450 1 1 63535647 10000 "

Looking with a hex editor, all the above whitespace are 20's.

From the documentation, I've constructed the following table...

CREATE TABLE MQIC.DBO.ORDER_F
(
TRACER_ID NUMERIC (10,0),
DB_CREATE_DATE CHAR (8),
DB_UPDATED_DATE CHAR (8),
CREATE_DATE_KEY NUMERIC (10,0),
ORDER_DATE_KEY NUMERIC (10,0),
PATIENT_KEY NUMERIC (10,0),
ORDER_KEY NUMERIC (10,0),
PROVIDER_KEY NUMERIC (10,0),
LOCATION_KEY NUMERIC (10,0),
ORDER_TYPE_KEY NUMERIC (10,0),
STATUS_KEY NUMERIC (10,0),
PRIMARY_INSURANCE_KEY NUMERIC (10,0),
EXISTENCE NUMERIC (1,0),
DURATION NUMERIC (4,0),
NUMBER_OF_VISITS NUMERIC (3,0),
ACTIVITY_TRACER_ID NUMERIC (10,0),
AGE_KEY NUMERIC (10,0)
)

To Bulk Insert this, I've written the following...

BULK INSERT MQIC.DBO.ORDER_F
FROM 'E:MDataOrder_F.txt'
WITH
(
FORMATFILE = 'E:MDataOrder_F_format.txt'
)

and written the following format file...

9.0
17
1 SQLNUMERIC 0 10 "" 1 TRACER_ID ""
2 SQLCHAR 0 8 "" 2 DB_CREATE_DATE ""
3 SQLCHAR 0 8 "" 3 DB_UPDATED_DATE ""
4 SQLNUMERIC 0 10 "" 4 CREATE_DATE_KEY ""
5 SQLNUMERIC 0 10 "" 5 ORDER_DATE_KEY ""
6 SQLNUMERIC 0 10 "" 6 PATIENT_KEY ""
7 SQLNUMERIC 0 10 "" 7 ORDER_KEY ""
8 SQLNUMERIC 0 10 "" 8 PROVIDER_KEY ""
9 SQLNUMERIC 0 10 "" 9 LOCATION_KEY ""
10 SQLNUMERIC 0 10 "" 10 ORDER_TYPE_KEY ""
11 SQLNUMERIC 0 10 "" 11 STATUS_KEY ""
12 SQLNUMERIC 0 10 "" 12 PRIMARY_INSURANCE_KEY ""
13 SQLNUMERIC 0 1 "" 13 EXISTENCE ""
14 SQLNUMERIC 0 4 "" 14 DURATION ""
15 SQLNUMERIC 0 3 "" 15 NUMBER_OF_VISITS ""
16 SQLNUMERIC 0 10 "" 16 ACTIVITY_TRACER_ID ""
17 SQLNUMERIC 0 10 "
" 17 AGE_KEY ""

However... actually running this gives the following error...

Msg 4863, Level 16, State 4, Line 1
Bulk load data conversion error (truncation) for row 1, column 13 (EXISTENCE).
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".


Since this is my first time with this, I read the BOL items on Bulk Insert, Format Files, and each of the formatting attibutes, and made up two line "toy" examples for SQLCHAR and SQLINT, including two columns - all worked as expected.

It seemed that only SQLNUMERIC/SQLDECIMAL fell apart.

Even the following trivial example doesn't work for this field of data...

"7999163 "

CREATE TABLE MQIC.DBO.ORDER_F
(
TRACER_ID NUMERIC (10,0)
)

and

9.0
1
1 SQLNUMERIC 0 10 " " 1 TRACER_ID ""

or

9.0
1
1 SQLNUMERIC 0 10 "" 1 TRACER_ID ""

which give this error...


Msg 9803, Level 16, State 1, Line 1
Invalid data for type "numeric".
The statement has been terminated.

or

9.0
1
1 SQLNUMERIC 0 10 "/r/n" 1 TRACER_ID ""

which gives this error...

Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".


Also - the DB_CREATE_DATE and DB_UPDATED_DATE CHAR (8) were supposed to be dates in the format of mmddyyy but clearly there is no Date datatype in SQL-Server. I would suppose these need to be converted, but am unsure how. What is clear is that the data was dumped from Oracle in text form,

Any thoughts on this would be greatly appreciated...

Thanks!

View 1 Replies View Related

BULK INSERT Format File Problems With SQLNUMERICAL In SQL-Server 2005 Express

May 24, 2006

I'm trying to set up a BULK INSERT Format File for some data that I've been sent, which, according to the data documentation, comes in fixed-width format fields (no delimiters except for end-of-row 0D0A) in SQL-Server 2005 Express.

The following is the first line...
"7999163 09182003 56586 56477 3601942 1278 22139 1102 113 118 51450 1 1 63535647 10000
7999162 09182003 56586 56477 3601942 1279 22139 1102 113 118 51450 1 1 63535647 10000 "

Looking with a hex editor, all the above whitespace are 20's.

From the documentation, I've constructed the following table...

CREATE TABLE MQIC.DBO.ORDER_F
(
TRACER_ID NUMERIC (10,0),
DB_CREATE_DATE CHAR (8),
DB_UPDATED_DATE CHAR (8),
CREATE_DATE_KEY NUMERIC (10,0),
ORDER_DATE_KEY NUMERIC (10,0),
PATIENT_KEY NUMERIC (10,0),
ORDER_KEY NUMERIC (10,0),
PROVIDER_KEY NUMERIC (10,0),
LOCATION_KEY NUMERIC (10,0),
ORDER_TYPE_KEY NUMERIC (10,0),
STATUS_KEY NUMERIC (10,0),
PRIMARY_INSURANCE_KEY NUMERIC (10,0),
EXISTENCE NUMERIC (1,0),
DURATION NUMERIC (4,0),
NUMBER_OF_VISITS NUMERIC (3,0),
ACTIVITY_TRACER_ID NUMERIC (10,0),
AGE_KEY NUMERIC (10,0)
)

To Bulk Insert this, I've written the following...

BULK INSERT MQIC.DBO.ORDER_F
FROM 'E:MDataOrder_F.txt'
WITH
(
FORMATFILE = 'E:MDataOrder_F_format.txt'
)

and written the following format file...

9.0
17
1 SQLNUMERIC 0 10 "" 1 TRACER_ID ""
2 SQLCHAR 0 8 "" 2 DB_CREATE_DATE ""
3 SQLCHAR 0 8 "" 3 DB_UPDATED_DATE ""
4 SQLNUMERIC 0 10 "" 4 CREATE_DATE_KEY ""
5 SQLNUMERIC 0 10 "" 5 ORDER_DATE_KEY ""
6 SQLNUMERIC 0 10 "" 6 PATIENT_KEY ""
7 SQLNUMERIC 0 10 "" 7 ORDER_KEY ""
8 SQLNUMERIC 0 10 "" 8 PROVIDER_KEY ""
9 SQLNUMERIC 0 10 "" 9 LOCATION_KEY ""
10 SQLNUMERIC 0 10 "" 10 ORDER_TYPE_KEY ""
11 SQLNUMERIC 0 10 "" 11 STATUS_KEY ""
12 SQLNUMERIC 0 10 "" 12 PRIMARY_INSURANCE_KEY ""
13 SQLNUMERIC 0 1 "" 13 EXISTENCE ""
14 SQLNUMERIC 0 4 "" 14 DURATION ""
15 SQLNUMERIC 0 3 "" 15 NUMBER_OF_VISITS ""
16 SQLNUMERIC 0 10 "" 16 ACTIVITY_TRACER_ID ""
17 SQLNUMERIC 0 10 "
" 17 AGE_KEY ""

However... actually running this gives the following error...

Msg 4863, Level 16, State 4, Line 1
Bulk load data conversion error (truncation) for row 1, column 13 (EXISTENCE).
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".


Since this is my first time with this, I read the BOL items on Bulk Insert, Format Files, and each of the formatting attibutes, and made up two line "toy" examples for SQLCHAR and SQLINT, including two columns - all worked as expected.

It seemed that only SQLNUMERIC/SQLDECIMAL fell apart.

Even the following trivial example doesn't work for this field of data...

"7999163 "

CREATE TABLE MQIC.DBO.ORDER_F
(
TRACER_ID NUMERIC (10,0)
)

and

9.0
1
1 SQLNUMERIC 0 10 " " 1 TRACER_ID ""

or

9.0
1
1 SQLNUMERIC 0 10 "" 1 TRACER_ID ""

which give this error...


Msg 9803, Level 16, State 1, Line 1
Invalid data for type "numeric".
The statement has been terminated.

or

9.0
1
1 SQLNUMERIC 0 10 "/r/n" 1 TRACER_ID ""

which gives this error...

Msg 4832, Level 16, State 1, Line 1
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".


Also - the DB_CREATE_DATE and DB_UPDATED_DATE CHAR (8) were supposed to be dates in the format of mmddyyy but clearly there is no Date datatype in SQL-Server. I would suppose these need to be converted, but am unsure how. What is clear is that the data was dumped from Oracle in text form,

Any thoughts on this would be greatly appreciated...

Thanks!

View 5 Replies View Related

Binary

Dec 31, 2007

i am using asp.net 2.0 with c#.
i have database - mssql server.
in that i have tuser table in that table i have password feild which datatype is Binary.
when i am entered password in asp.net application that time runtime error is convert the string to binary.
my code is---string myByte = Stingtest;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();Byte[] bytes = encoding.GetBytes(myByte);myByte = "";
myByte = encoding.GetString(bytes);
 
 
objClsDllSql.sqlCon = objReadIniFile.funReadIniSql();
objClsDllSql.sqlCon.Open();objVarIni.sqlDA = new SqlDataAdapter("select * from tUser ", objClsDllSql.sqlCon);
objVarIni.sqlDA.Fill(objVarIni.sqlDS, "tUser");
objVarIni.sqlDT = objVarIni.sqlDS.Tables["tUser"];
 strSqlCmdText = "insert into tUser values( " + Convert.ToInt32(txtUserCode.Text) + " , "+
" " + " ' " + txtUserID.Text + " ' " + ", "+" " + " ' " +txtFirstName.Text + " ' " + ", "+
" " + " '" + txtLastName.Text + "'" + ", "+" " + myByte + ", "+
" " + "'" + txtUserType.Text + "'" + ", "+ " " + "'" + dtpWarningDate.SelectedDate + "'" + " , "+
" " + "'" + dtpExpireDate.SelectedDate + "'" + ", "+" " + "'" + drpdwnStatus.SelectedItem.Text + "'" + ", "+
" " + "'" + Session["LoginName"].ToString() + "'" + ", "+" " + "'" + dtpCreateDate.SelectedDate.ToString() + "'" + ", "+
" " + "'" + txtUpDatedBy.Text + "'" + ", "+
" " + "'" + dtpUpdateDate.SelectedDate.ToString() + "'" + ")";
 
pls help me .
its really urgent.
gayatri

View 1 Replies View Related

SSMS Express: Create TABLE &&amp; INSERT Data Into Table - Error Msgs 102 &&amp; 156

May 18, 2006

Hi all,

I have SQL Server Management Studio Express (SSMS Express) and SQL Server 2005 Express (SS Express) installed in my Windows XP Pro PC that is on Microsoft Windows NT 4 LAN System. My Computer Administrator grants me the Administror Privilege to use my PC. I tried to use SQLQuery.sql (see the code below) to create a table "LabResults" and insert 20 data (values) into the table. I got Error Messages 102 and 156 when I did "Parse" or "Execute". This is my first time to apply the data type 'decimal' and the "VALUES" into the table. I do not know what is wrong with the 'decimal' and how to add the "VALUES": (1) Do I put the precision and scale of the decimal wrong? (2) Do I have to use "GO" after each "VALUES"? Please help and advise.

Thanks in advance,

Scott Chang

///////////--SQLQueryCroomLabData.sql--///////////////////////////
USE MyDatabase
GO
CREATE TABLE dbo.LabResults
(SampleID int PRIMARY KEY NOT NULL,
SampleName varchar(25) NOT NULL,
AnalyteName varchar(25) NOT NULL,
Concentration decimal(6.2) NULL)
GO
--Inserting data into a table
INSERT dbo.LabResults (SampleID, SampleName, AnalyteName, Concentration)
VALUES (1, 'MW2', 'Acetone', 1.00)
VALUES (2, 'MW2', 'Dichloroethene', 1.00)
VALUES (3, 'MW2', 'Trichloroethene', 20.00)
VALUES (4, 'MW2', 'Chloroform', 1.00)
VALUES (5, 'MW2', 'Methylene Chloride', 1.00)
VALUES (6, 'MW6S', 'Acetone', 1.00)
VALUES (7, 'MW6S', 'Dichloroethene', 1.00)
VALUES (8, 'MW6S', 'Trichloroethene', 1.00)
VALUES (9, 'MW6S', 'Chloroform', 1.00)
VALUES (10, 'MW6S', 'Methylene Chloride', 1.00
VALUES (11, 'MW7', 'Acetone', 1.00)
VALUES (12, 'MW7', 'Dichloroethene', 1.00)
VALUES (13, 'MW7', 'Trichloroethene', 1.00)
VALUES (14, 'MW7', 'Chloroform', 1.00)
VALUES (15, 'MW7', 'Methylene Chloride', 1.00
VALUES (16, 'TripBlank', 'Acetone', 1.00)
VALUES (17, 'TripBlank', 'Dichloroethene', 1.00)
VALUES (18, 'TripBlank', 'Trichloroethene', 1.00)
VALUES (19, 'TripBlank', 'Chloroform', 0.76)
VALUES (20, 'TripBlank', 'Methylene Chloride', 0.51)
GO
//////////Parse///////////
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '6.2'.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'VALUES'.
////////////////Execute////////////////////
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '6.2'.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'VALUES'.

View 7 Replies View Related

Binary Serialization

Mar 9, 2007

Hello,I am trying to serialize (binary) a class and save it in a database. I followed a few examples I found in internet and this is what I came up with: 1 ' Rows
2 <Serializable()> _
3 Public Class Rows
4 Implements ISerializable
5
6 Private _Rows As New Generic.List(Of Row)
7 Public Property Rows() As Generic.List(Of Row)
8 Get
9 Return _Rows
10 End Get
11 Set(ByVal value As Generic.List(Of Row))
12 _Rows = value
13 End Set
14 End Property ' Rows
15
16 ' New
17 Public Sub New()
18 End Sub ' New
19
20 ' New
21 Public Sub New(ByVal siRows As SerializationInfo, ByVal scRows As StreamingContext)
22 End Sub ' New
23
24 ' GetObjectData
25 Public Sub GetObjectData(ByVal siRows As SerializationInfo, ByVal scRows As StreamingContext) Implements ISerializable.GetObjectData
26
27 siRows.AddValue("Rows", Me.Rows)
28
29 End Sub ' GetObjectData
30
31 Public Sub Serialize(ByVal filename As String)
32
33 Dim sRows As Stream = Stream.Null
34 Try
35 sRows = File.Open(filename, FileMode.Create, FileAccess.ReadWrite)
36 Dim bfRows As New BinaryFormatter
37 bfRows.Serialize(sRows, Me)
38 Finally
39 sRows.Close()
40 End Try
41
42 End Sub ' Serialize
43
44 Public Shared Function Deserialize(ByVal filename As String) As Rows
45
46 Dim sRows As Stream = Stream.Null
47 Try
48 sRows = File.Open(filename, FileMode.Open, FileAccess.Read)
49 Dim bfRows As New BinaryFormatter
50 Return CType(bfRows.Deserialize(sRows), Rows)
51 Finally
52 sRows.Close()
53 End Try
54
55 End Function ' Deserialize
56
57 End Class ' Rows
 After serializing the class I need to save it in an a SQL 2005 database.But all the examples I followed use the filename ... Anyway, do I need to do something to save this into an SQL 2005 database or can I use it as follows? And how can I use this?This is the first time I do something like this so I am a little bit confused.Thanks,Miguel    

View 1 Replies View Related

Binary Problem

Aug 1, 2007

Hy friends!I'm new in WebApplications that have SQL SERVER DB.My problem is that...In the DataBase I have a table with varbinary column and in the program I want save in this column a value of binary[] variable! How I can make it?Another question.... If I want select (by a query in the application) the value of the binary column, where I store it? because if I want select an integer value I take this in a int variable, and if I want select an string value from a DataBase I take this in a string variable..but How I can make it with binary column?Thanks in advance!! 

View 1 Replies View Related

Binary Data

Dec 28, 2007

Hello,
I have a table which uses binary data to store passwords.  How do I view the contents of the "binary data" column, ie. the passwords?  It just shows it as <binary data>?

View 5 Replies View Related

SQL Binary To C# Byte[]

Apr 6, 2004

I have a binary column with length 20 in SQL server table. I store dynamically C# byte[] value range from 0 to 19. So for example, If I store length of 16 and when I try to retrive it back into byte [] in C# it returns whole length 20. When I see in debug it has value from 0 to 15 which I want to use but from 16 to 19 is zero. How can I get just length value which I stored.

I use DataRow to get whole row and from the row object I extract byte [] based on column name.

Thank you in advance....

View 1 Replies View Related

Binary File

Aug 5, 2004

Can someone firecct me to instructions on how to download a Binary file in a asp.net application.

I have a sql 2000 db that has a field that contains files and my users need access to them via my web app.

View 2 Replies View Related







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