actually I have developed a web application in MVC 5.0 with Entity framework 6.0, sql server ..
I tried to query a sum value which is Amount(Float in sql server)
SearchDetails.Sum(total => Convert.ToDecimal(total.Amount));
getting
input string was not in a correct format
I took database backup and I tried to run from my side I am getting the value
I have verified in the database all the values are in correct format
I tried to print the values
total.Amount
getting a comma
","
instead of dot
"."
in my PC value is like 300.00 but the same in client PC getting 300,00 ?
Please help.
I have Add this in
in globlization section SET culture = en-US
this solved my issue
Thanks
Related
I have a stored procedure created in MySQL DB. This database is accessed as linked server through Microsoft SQL Server 2012 using Microsoft SQL Server Management Studio. The provider selected while creating linked server is "Microsoft OLE DB Provider for ODBC Drivers".
When I run following as text from Report builder 3.0 it runs fine and fetch data.
EXEC('CALL storedProcedureName(''string1'', ''string2'', ''string3'')') AT LinkedServerName;
But when I try to replace string1, string2, string3 with parameter name parameter1, parameter2, parameter3 as:
EXEC('CALL storedProcedureName(#parameter1, #parameter2, #parameter3)') AT LinkedServerName;
I get error:
Could not execute statement on remote server 'LinkedServerName'.
(Microsoft SQL Server, Error: 7215)
And when I try:
EXEC('CALL storedProcedureName('#parameter1', '#parameter2', '#parameter3')') AT LinkedServerName;
I get the prompt to enter values for parameter1, parameter2, parameter3. But when I enter the values and click ok, I get error:
Incorrect syntax near '#parameter1'. (Microsoft SQL Server, Error: 102)
Question: Am I missing something in syntax or is this a bug?
The linked server has:
"RPC" and "RPC out" set to True.
And the OLEDB provider has:
Enabled allow inprocess
Enabled dynamic parameter
I believe you have to call it like the below. So params become strings wrapped in single quotes:
EXEC('CALL storedProcedureName('''+#parameter1+''', '''+#parameter2+''', '''+#parameter3+''')') AT LinkedServerName;
I know this is an older question but the accepted answer is open to SQL Injection and I think it's important to offer a more secure method.
You really want to use a parameterized query
EXEC('CALL storedProcedureName(?,?,?)',#parameter1, #parameter2, #parameter3) AT LinkedServerName;
I know this works for oracle and it should work for MySql as well.
SQLCEToolbox looks very promising.
I installed it, opened VS 2012, selected Tools | SQL Server Compact Toolbox, quickly and easily set up a connection to my sdf database, which I had (also quickly and easily) created in WebMatrix.
I then right-clicked the database in SQLCEToolbox's treeview and selected Import from CSV file.
Note: One must explicitly specify the column names on the first line in the file (line/row 0) and explicitly add the ID/Primary Key/Identity vals (if you have such a column).
Once I fixed the various formatting errors with my csv file, it seemed to import well. But I got this err msg:
Error Code: 80004005
Message : The data was truncated while converting from one data type to another. [ Name of function(if known) = ]
Minor Err.: 25920
Source : SQL Server Compact ADO.NET Data Provider
My data is in the format:
1,SomeCategory,SomeName,SomeURL,Longitude,Latitude
As an example, here's a sample line:
3,ArtGallery, Henry Miller Memorial Library,http://www.henrymiller.org/, -121.7537834,36.2207945
Except for the int ID column, they are all nvarchar(50) columns. So I realized that some of my URLs were longer than 50 chars; so, in WebMatrix, I modified that column to be nvarchar(128). On trying again to import, apparently that first problem was solved, but now I get:
Error Code: 80004005
Message : The column cannot be modified. [ Column name = ID ]
Minor Err.: 25004
Source : SQL Server Compact ADO.NET Data Provider
Err. Par. : ID
Okay, I reason, since the ID column is to be automatically updated, I shouldn't have it in my csv file. So I changed it to this:
Category,Name,URL,Longitude,Latitude
ArtGallery, Henry Miller Memorial Library,http://www.henrymiller.org/, -121.7537834,36.2207945
...but when I tried importing the records that way (with "ID" removed from row 0 and the corresponding val from each line/record), and try to import, I get:
Error Code: 80004005
Message : The data was truncated while converting from one data type to another. [ Name of function(if known) = ]
Minor Err.: 25920
Source : SQL Server Compact ADO.NET Data Provider
I tried to post a question at http://sqlcetoolbox.codeplex.com/, but trying to do so simply took me to a generic codeplex area (rather than a SQL CE Toolbox-specific area).
So what might be the problem here (the revised row 0 and another sample row are shown below) now? The longest URL is only 98 chars.
What's wrong with my data or methodology?
I am trying to post a date to a dateTime column in a SQL Server 2008 R2 database, but I have run into many problems that I don't know what are the causes.
First, I used this code but I got the error:cannot convert string to date.
ADOOF.SQL.Text:='UPDATE OFTab SET CA='''+ CA.Text + ''', demandeClient=''' + DateTimeToStr(demandeClient.DateTime) + ''' WHERE ID='''+ ADOOF.FieldByName('ID') + '''';
ADOOF.ExecSQL;
Second, I have used parameters:
ADOOF.SQL.Text:='UPDATE OFTab SET CA='''+ CA.Text + ''', demandeClient=:demande_client WHERE ID='''+ ADOOF.FieldByName('ID') + '''';
ADOOF.Parameters.ParamByName('demande_client').Value:= demandeClient.Date;
ADOOF.ExecSQL;
But I got the error: Parameter (demande_client) not found.
I googled this problem and I found a suggestion by Embarcadero saying that the parametres sould be created before calling the ADOQuery like this:
ADOOF.SQL.Text:='UPDATE OFTab SET CA='''+ CA.Text + ''', demandeClient=:demande_client WHERE ID='''+ ADOOF.FieldByName('ID') + '''';
ADOOF.Parameters.ParseSQL(ADOOF.SQL.Text, True);
ADOOF.Parameters.ParamByName('demande_client').Value:= demandeClient.Date;
ADOOF.ExecSQL;
Finely I removed the connection Persist Security Info but always the same problem.
Please, any suggestions.
INFO: I am using MICROSOFT OLE DB Provider For SQL Server.
in your first example use
FormatDateTime('YYYYMMDD hhmmss',demandeClient.DateTime)
instead of
DateTimeToStr(demandeClient.DateTime)
This is because DateTimeToStr without formatsettings uses your localized machine settings and your database just might or might not like the format. Using FormatDateTime also gets rid of ambiguities: consider 01/02/03, for some people on the world this is january 2nd 2003 but for others 1st of februari 2003 and even some will say 2001, februari 3rd. YYYYMMDD is universal. 20030201 is always 1st of februari 2003.
It can depend on how you connect to your DB (drivers).
You can try to explicit that you are using a Date:
ADOOF.Parameters.ParamByName('demande_client').DataType:= ftDateTime;
ADOOF.Parameters.ParamByName('demande_client').AsDateTime:= demandeClient.Date;
I will strongly suggest to use SQL Native Client 11 when you are working with SQL Server 2008 R2. New SQL Server 2008 data types (including DATE, TIME, DATETIME2, and DATETIMEOFFSET) are not supported by the SQL Server 2000 OLEDB provider.
Your second code sample should work. Check that you have TADOQuery.ParamCheck = True.
I'm making a web app that needs to load and save UTF-8 (Korean, specifically) characters from a DB. I've been given an account on the Oracle 10g server, but it saves VARCHAR2 type columns as ASCII7, with each UTF-8 character taking 2 VARCHAR2 slots.
I assumed that since iBatis is writing in the same way that it is reading, if I treat everything from input to output as UTF-8 I will have no problems, but any Korean characters I input come out garbled.
Is there a way to do this properly without messing up the (someone else's) DB?
Further information:
I've previously been able to load Korean strings using:
ResultSet rs = ps.executeQuery();
String koreanString = new String(rs.getBytes("colname"), "euc-kr");
And write Korean strings to db using:
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, new String(koreanString.getBytes("euc-kr"), "ISO-8859-1"));
Attempts to change the JDBC connection url result in this message:
Description
Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
[ip]:myTablespace?useUnicode=true&characterEncoding=UTF-8
error dump
javax.servlet.ServletException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
[ip]:myTablespace?useUnicode=true&characterEncoding=UTF-8
at jeus.servlet.jsp2.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:859)
at jeus.servlet.jsp2.runtime.PageContextImpl.handlePageException(PageContextImpl.java:789)
at jeus_jspwork._jsp._500_managerAdmin_5fjsp._jspService(_500_managerAdmin_5fjsp.java:452)
at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:95)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:147)
at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:365)
at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:284)
root cause
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
[ip]:myTablespace?useUnicode=true&characterEncoding=UTF-8
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:441)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.ibatis.common.jdbc.SimpleDataSource.popConnection(SimpleDataSource.java:580)
at com.ibatis.common.jdbc.SimpleDataSource.getConnection(SimpleDataSource.java:222)
at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.init(JdbcTransaction.java:48)
at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:89)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:82)
at [].admRole.getCount(admRole.java:44)
at jeus_jspwork._jsp._500_managerAdmin_5fjsp._jspService(_500_managerAdmin_5fjsp.java:145)
at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:95)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:147)
at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:365)
at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:284)
As I stated in the question, strings are stored and retrieved correctly if they are re-encoded as EUC-KR before being turned into ISO-8859-1 (to save, or vice versa to retrieve).
I modified the two following classes:
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap
com.ibatis.sqlmap.engine.mapping.result.ResultMap
In both cases, I took the Object[] array (parameters and columnValues), casted to String, and applied the encoding transformations.
I am not using oracle for quite a while, but I have some confidence that this is reason of your "listener does not currently know of SID given" error: Can I force JDBC Driver use UTF-8 Charset to encode?
I am a Chinese developer so the character encoding problem is pretty much the same(we are mostly using GBK character set here). As far as I can remember, "but it saves VARCHAR2 type columns as ASCII7" means that your oracle instance is a non-unicode installation?
The force use of string.getBytes(charset) above JDBC layer is really really bad in terms of maintenance and data interpretability(the string data is displayed as a mess to DBA; DBA can not use SQL to perform any string comparison on this column, etc). So my advice is try to contact your DBA and get the database working with unicode first, since Oracle is very capable of handling unicode data.
Dim NorthWindOledbConnection As String = "Provider=SQLOLEDB;DataSOurce=SARAN-PC\SQLEXPRESS;Integrated Security=ssp1;InitialCatalog=Sara"
Dim rs As New ADODB.Recordset()
rs.Open("select * from SecUserPassword", NorthWindOledbConnection, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic)
i tried to run this above code in visual studio 2008 - it shows the following error:
"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done"
Firstly, don't use ADO in VB.NET. Use ADO.NET.
Other than that, create a proper Connection object instead of passing around a string.
And fix your connection string. It's SSPI, not SSP1. And it's Data Source, not DataSOurce. And it's Initial Catalog, not InitialCatalog.
You are using a very very very old way to access a Database that has been used with Visual Basic 6 and older.
Check to use ADO.NET instead of old ADO. For example you can use this code that is "similar" to the code you are using (but is not the best way to access the data on VS2008)
OleDbConnection con= New OleDbConnection( **Your Connection String** )
con.Open()
Dim command As OleDbCommand = New OleDbCommand("select * from SecUserPassword", con)
sqlCommand .CommandType = CommandType.Text
Dim reader As OleDbDataReader = TheCommand.ExecuteReader()
While reader.Read()
System.Console.Write(reader(** Your Table Field Name** ).ToString())
End While
con.Close()
To view how to create a correct connection String see the site http://www.connectionstrings.com/
If you want to access to an SQL Server database also you can use the SQLClient namespace instead the OleDb. For example System.Data.SqlClient.SqlConnection instead the OleDbConnection to provide better performance for SQL Server
The link below is an article that gives a great breakdown of the 6 scenarios this error message can occur:
Scenario 1 - Error occurs when trying to insert data into a database
Scenario 2 - Error occurs when trying to open an ADO connection
Scenario 3 - Error occurs inserting data into Access, where a fieldname has a space
Scenario 4 - Error occurs inserting data into Access, when using adLockBatchOptimistic
Scenario 5 - Error occurs inserting data into Access, when using Jet.OLEDB.3.51 or ODBC driver (not Jet.OLEDB.4.0)
Scenario 6 - Error occurs when using a Command object and Parameters
http://www.adopenstatic.com/faq/80040e21.asp
Hope it may help others that may be facing the same issue.