SQL 2008 remove smart quotes before data insert - json

I have a VB.net web service that inserts data into a SQL 2008 DB. A lot of the data is being pulled from a word document. So we recently ran into an issue where smart quotes and a funky looking apostrophe was inserted into the data column. It inserted fine. My issue is that we are pulling the data from the DB and sending it back to the user as JSON. So when the user tries to look at the data they get an unexpected end of JSON when it tries to read the funky characters.
Can I do something in my VB code before I insert it or is it easier to do in the SQL insert stored procedure? Any suggestions would be greatly appreciated.

Related

SSIS - OleDB connection not updating data, inserted thru SQLBulkCopy with SQL Connection

I have created Ole DB connection to execute different SQL task across SSIS package. Its working fine too.
In one of task where i need to do insert data into table, used SQLBulkCopy as i have dynamic tables and columns based on getting files from different sources.
SQLBulkCopy only works with SqlConnection, so i opened SqlConnection, executed SqlBulkCopy. This is also working fine.
After done with SqlBulkCopy, i have created Sql Task which updates metadata of inserted rows, for e.g. Count, Min & Max date and so on in different table.
This table is not getting updated and if i execute stored procedure from Sql Management Studio, it works as expected.
So my assumption is that, Ole DB connection is not able to get the latest data Data inserted thru SQL Connection.
I may be wrong, but not sure why i can see sql execution task successful but still table is not updated.
Am i missing anything here?
My bad.
Instead of passing data type as long (int in SQL), i was passing it as Varchar.
I was looking from last few hours and as soon as i post question here, it strikes me to check the data type.
Hope it will help somebody.

Insert HTML data to SQL Server

I'd like to insert HTML data in SQL Server using ASP.NET and a stored procedure but I'm not able to insert all the tags and double quotes. Any help would be appreciated.
You can use base64 encoding to store and decoding when reading the data
First try to strip down your problem to the basics:
SQL-Server has a datetype nvarchar(max). This typ can store a lot of data. All characters that "arive" at the database can be inserted. You shoul first check, what data arives at the server. An easy way is SQL prifiler. You should see the data in Profiler, that "arives" at the database. If things are broken here (i.e.wrong encoding) you should the way up to you application.
Which way comes the data? You only mention ASP.NET. You can connect to the database using ODBC, JDBC, OLEDB or ADO-driver (there might be more). Data can be converterd on this way. You can set up a Trace an see what happens. The easy way normaly is the fastest: Check the options of the driver/try other settings. Most drivers have only a small number of options. If you can not find the problem here...
Your application. Strip it down to the minimal functionality: Establish a connection to the database an insert some data into a table. Does this work? Does it work with different collation? Does it word with unicode data?
Maybe a better question could better be answered.

Import .CSV values to SQL Server 2008 using MFC Application

I have created dialog based application in MFC from here i am connecting the database SQL Server 2008.
up to now coonection was ok.
here i have the .CSV file for inserting large amount of data.How can i insert the values using MFC application with .CSV file in to SQL Server 2008.
You have to read the CSV (Comma Separated Values) file Character by Character, whenever you encounter a ',' you can take it as on field and on a line break it will be end of record.
Please see This link for the detailed code.
Then you have simultaneously write into the database table, whenever you encounter the End of Record.
This link or this provides a description on how to insert data into the database table using MFC.
Hopefully these will get you started.

Excel SQL Server Data Connection

Perhaps someone could provide some insight into a problem I have.
I have a SQL Server database which receives information every hour and is updated from a stored procedure using a Bulk Insert. This all works fine, however the end result is to pull this information into Excel.
Establishing the data connection worked fine as well, until I attempted some calculations. The imported data is all formatted as text. Excel's number formats aren't working so I decided looking at the table in the database.
All the columns are set to varchar for the Bulk Insert to work so I changed a few to numeric. Refreshed in Excel and the calculations worked.
After repeat attempts I've not been able to get the Bulk Insert to work, even generating a format file with bcp it still returned errors on the insert. Could not convert varchar to numerical, after some further searching it was only failing on one numerical column which is generally empty.
Other than importing the data with VBA and converting it like that or adding zero to every imported value so Excel converts it.
Any suggestions are welcome.
Thanks!
Thanks for the replies I had considered using =value() in Excel but wanted to try avoid the additional formulas.
I was eventually able to resolve my problem by generating a format file for the Bulk Insert using the bcp utility. Though getting it to generte a file proved tricky enough below is an example of how I generated it.
At an elevated cmd:
C:\>bcp databasename.dbo.tablename format nul -c -x -f outputformatfile.xml -t, -S localhost\SQLINSTANCE -T
This generated an xml format file for the specific table. As my table had two additional columns which weren't in the source data I edited the XML and removed them. They were uniqueid and getdate columns.
Then I changed the Bulk Insert statement so it used the format file:
BULK INSERT [database].[dbo].[tablename]
FROM 'C:\bulkinsertdata.txt'
WITH (FORMATFILE='C:\outputformatfile.xml',FIRSTROW=3)
Using this method I was able to use the numeric and int datatypes successfully. Going back to Excel when the data connection was refreshed it was able to determine the correct datatypes.
Hope that helps someone!

problem occuring when i am inserting date

while inserting date mysql server takes the year and day correctly but the month is defaultly taking januavary into the database.
i am using mysql server version 5.0.22
i am inserting the date though application.
the application was developed by using Springs web mvc frame-work and Hibernate.
Can you display the mysql INSERT statement which is being used to insert the data into the database? This would indicate whether it is a malformed INSERT statement or whether it is a valid statement using incorrect data.
Once you know what is happening, you can track down where the problem really is. I would guess it is a faulty date-parsing function.
Another possibility is that the software is expecting the date in European format (dd-mm-yyyy) and getting the entry in US format (mm-dd-yyyy) or vice-versa. And this is causing parsing errors.