Quantcast
Channel: SQL Server Data Access forum
Viewing all 4164 articles
Browse latest View live

Convert nvarchar to integer in sql server.

$
0
0

hii guys

I have build a database with columns as "Nvarchar". Data is being inserted by using ssis package to import from excel files to the database.

My problem is that when I am executing a query in SQL SERVER 2005 to select from database, I need to convert the data from "Nvarchar" to integer. I have use The cast function, convert function and i am getting an error :

"Conversion failed when converting the nvarchar value '10,15' to data type int."

The different statements i have used are below:

a)

select 
      case 
          when isnumeric([cost]) = 1 then 
                  cast([cost] AS int)
          else
                  NULL
     end

b)

SELECT st([Cost] as INT)
        FROM [mytable]

c)

SELECT Convert(INT,[cost
        FROM [mytable]

I really need help please!!!


multiple versions of oracle ole.db

$
0
0
I currently have linked server  with Oracle ole.db version 12 connecting to an Oracle 12c database. I want to install ODAC 19c for oracle ole.db 19c to connect to a development oracle database version 19c. Can i install the oracle 19c version of ole.db as another provider so that I can create a linked server to access the 19c database? I don't want to cause any conflict with the production oracle 12c linked server.

Found a bug in SqlBulkCopy - where can I report it?

$
0
0

Hi,

I use bulk copy to upload and process data from multiple servers. Each day, each server uploads data to the same table and notifies primary server that it finished its work. Once all servers notify, main server runs processing procedure.

From time to time the process failed for no apparent reason. At last I pinpointed the source of problem - data from random server was still being uploaded, but it already sent notification. My code runs synchronously - upload method first, then notification method.

I reviewed my method and then I previewed "WriteToServer" method using Resharper. Here's what I found:

public void WriteToServer(DataTable table, DataRowState rowState)
    {
      SqlConnection.ExecutePermission.Demand();
      if (table == null)
        throw new ArgumentNullException(nameof (table));
      if (this._isBulkCopyingInProgress)
        throw SQL.BulkLoadPendingOperation();
      SqlStatistics statistics = this.Statistics;
      try
      {
        statistics = SqlStatistics.StartTimer(this.Statistics);
        this._rowStateToSkip = rowState == (DataRowState) 0 || rowState == DataRowState.Deleted ? DataRowState.Deleted : ~rowState | DataRowState.Deleted;
        this._rowSource = (object) table;
        this._dataTableSource = table;
        this._SqlDataReaderRowSource = (SqlDataReader) null;
        this._rowSourceType = SqlBulkCopy.ValueSourceType.DataTable;
        this._rowEnumerator = table.Rows.GetEnumerator();
        this._isAsyncBulkCopy = false;
        this.WriteRowSourceToServerAsync(table.Columns.Count, CancellationToken.None);
      }
      finally
      {
        SqlStatistics.StopTimer(statistics);
      }
    }

In line 19 the write process is initialized asynchronously, but it doesn't wait to complete - the upload runs on different thread and the main thread returns from method without knowing whether upload finished or not.

Where can I report it?

Regards,

Mariusz

'Microsoft.SqlServer.Management.IRegistrationService' not found

$
0
0

Hello,

Click any menu on SSMS, it will give error: 'Microsoft.SqlServer.Management.IRegistrationService' not found .

From other device connect to the database server, I can open the database by click-to-open. all normal.

on the server, I can run query to open data base.

please give advice what persmission or config for this issue.

(SSMS as adminstrator. setup the sql program folder full control, and resintall SQL server. nothing help.

Try to isntall net frame 4.8, it says already isntalled new version)

tks n brgds

Liu Wei

"Memory allocation failure" error using MSOLEDBSQL

$
0
0

We have a legacy VB6 application which we recently changed from SQLOLEDB to MSOLEDBSQL because our network admins want to disable TLS1.0.

Since then we're seeing the error "Memory allocation failure", we've never seen this in the 18+ years we've been using SQLOLEDB.  This happens to about a dozen users every day and there's no obvious pattern.  The VB6 application exclusively calls stored procedures, there's no "direct" queries/updates/inserts/deletes.  Another point worth noting is that the application creates a single connection on startup and uses this for everything, so typically the connection is active for the whole working day.  Here's the database connection code:

Set lobjConnection = New ADODB.Connection

With lobjConnection
    .Provider = "MSOLEDBSQL"
    .Properties("Data Source").Value = "MyServer"
    .Properties("Initial Catalog").Value = "MyDatabase"
    .Properties("Integrated Security").Value = "SSPI"
    .CursorLocation = adUseClient
    .Open
    .Execute "SET QUOTED_IDENTIFIER OFF"
    .Execute "SET IMPLICIT_TRANSACTIONS OFF"
    .Execute "SET CURSOR_CLOSE_ON_COMMIT OFF"
    .Execute "SET ANSI_WARNINGS OFF"
    .Execute "SET ANSI_PADDING OFF"
    .Execute "SET ANSI_NULLS OFF"
    .Execute "SET CONCAT_NULL_YIELDS_NULL OFF"
    .Execute "SET LANGUAGE US_ENGLISH"
    .Execute "SET DATEFORMAT DMY"
    .Execute "SET DATEFIRST 7"
End With

To be clear, there have not been any SQL Server configuration changes, the only change is from SQLOLEDB to MSOLEDBSQL in the client application.

Has anyone else seen this behaviour?  It's inconvenient and I'm not sure how to go about investigating it further.

Thanks in advance

Unable to complete login process due to delay in opening server connection

$
0
0

We have had new servers installed and i am trying to set up the system to run our database.  I have been trying to get the connection from the server which holds the application to the server with the database on. 

To test the connection i used the Data Sources (ODBC) set up window. 

I have 2 SQL drivers the standard one and the Native client:
SQL Server                                               6.01.7601.17514
SQL Server Native Client 10.0                  2009.100.1600.01

The standard one works fine but the native client keeps failing with the following error
Connection Failed
SQL State 08001
SQL Server Error: 0
[Microsoft][SQL Server Native Client 10.0] Unable to complete login process due to delay in opening server connection.

The problem is that the application uses the Native Client to run so i need that one connecting.
I have the same 2 drivers on the server with the database on and they both work fine on there.  I have also tried using the IP address instead of the server name but i still get the same outcome.  TCP/IP and named pipes are enabled for the Native Client.

Anyone any ideas?

Slow or failing connections on Linux with the ODBC Driver 17 for SQL Server

$
0
0

We are using:

SUSE Linux Enterprise Server 12 (x86_64)
VERSION = 12
PATCHLEVEL = 4

unixODBC 2.3.7 and libmsodbcsql-17.4.so.2.1

The connection is being made to SQL Server 13.00.5101.09 and also 11.00.7462.06

We intermittently get this error:

C ERROR: -1 in function SQLConnectWithRetry (SQLConnectWithRetry) [line 3226]
C (99) [HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired
C ERROR: -1 in function SQLConnectWithRetry (SQLConnectWithRetry) [line 3226]
C (258) [08001] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x102
C ERROR: -1 in function SQLConnectWithRetry (SQLConnectWithRetry) [line 3226]
C (258) [08001] [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
C Connection 1 failed using Driver=ODBC Driver 17 for SQL

When we increase the ODBC timeout to 120 seconds, the connection works, but it takes a long time to connect.

A wireshark trace seems to indicate that there is port re-use:

 TCP 74 [TCP Retransmission] 40425 → 6201 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=1500166724 TSecr=0 WS=128

 [TCP Port numbers reused] 40425 → 6201 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=1500165693 TSecr=0 WS=128

..

TCP 74 [TCP Retransmission] 40425 → 6201 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=1500168740 TSecr=0 WS=128

ICMP 98 Echo (ping) request id=0x25b6, seq=180/46080, ttl=64 (no response found!)

We tried changing /proc/sys/net/ipv4/ip_local_port_range
from 9000 65499 to 10000 15000 and there was significant improvement, but the problem is still there.

We are using <Servername>\<Instance>,<port> to connect.

Does anyone have an idea why there is this delay in connecting to the server?

Thanks,

Gudmundur


Gudmundur Karlsson



Connect to DB1 and want to execute SP in DB2 and insert reulst in a table in DB1

$
0
0

Hello everyone,

Hello, I am able to run the sp below and get data

Exec "RPP_QRPT5051_JAY";1 N'%', N'%', N'%', N'%', {ts '2019-01-01 00:00:00'}

I would need to insert the returned data into a table in my database, but get errors below:

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'Exec'.
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ')'.

when I run the query:

 select *
into [OptiDB].[dbo].[2017]
from (Exec "RPP_QRPT5051_JAY";1 N'%', N'%', N'%', N'%', {ts '2019-01-01 00:00:00'})

Also tried the query:

SELECT * INTO [OptiDB].[dbo].[2017] FROM OPENROWSET ('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
'Exec "RPP_QRPT5051_JAY";1 N'%', N'%', N'%', N'%', {ts '2019-01-01 00:00:00'}')

and get the following error:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '%'.

Will appreciate any assistance on the correct syntax/procedure.

Regards,

Jay


Jay Tabatabai


SQL server 2005 issue

$
0
0

I'm not sure weather this is an app issue, or SQL issue, but I am trying to connect MetaComm Application server (create a DB connection (attached). however in SQL 2005, I'm getting "must have a compatibility level of 8.0"

I'm unsure if I'm doing the right thing, but if this could be possible only per DB then its gonna take a long time doing to all DB's..

I was hoping to do comparability level on username connection itself. How does this compatibility work with connections to.

SQL is set to "Mixed mode" as per the application instructions. By default, I'm assuming it's 9.0



The process cannot access the file because it is being used by another process

$
0
0

While trying to attach a mdf by using Management Studio Attach command I get the following error the main part of which is:

"…

CREATE FILE encountered operating system error 32(The process cannot access the file because it is being used by another process.) while attempting to open or create the physical file …  (Microsoft SQL Server, Error: 5123)

…"

I understand why this is happening. However, assuming that the message is not misleading I have two questions:

1.      How do I find out which process has the file? Is there a tool to determine this?

2.      Once I find out who is using the file how to I get the process to relinquish it? Again, is there a tool to do this?


Mike Reed

Backup server

$
0
0
How to backup Database to File server or Backup server ?

SQL Server 2005 X64 Linked Server error

$
0
0

We use Windows 2003 Server (64) on AMD64 and SQL Server 2005 Developer Edition x64 + SP1

 Problem:

I can not execute any sql on a linked server using the native Provider (SQLCLNI)

Example (create a linked server on the same machine, other database (msdb) and try to execute any simple select using OPENQUERY

 sp_addlinkedserver @server='ls',@srvproduct='SQLNCLI',@provider='SQLNCLI'

,@provstr='Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=msdb;Data Source=localhost;'

 Select*fromOPENQUERY(ls,'Select * from Sysobjects')

 Msg 7356, Level 16, State 1, Line 1

The OLE DB provider "SQLNCLI" for linked server "ls" supplied inconsistent metadata for a column. The column "name" (compile-time ordinal 1) of object "Select * from Sysobjects" was reported to have a "Incomplete schema-error logic." of 0 at compile time and 0 at run time.

 

Login timeout expired when using ODBC Driver 17 to connect to MS SQL Server 12.0 via Ubuntu 18.04.1 proxy server

$
0
0

Hi,

We are using a proxy server in order to connect to servers that only allow connecting from whitelisted IP addresses. When we connect to the SQL Server directly it works fine, but connecting via the proxy always results in Login timeout expired.

We use the same proxy and code for connecting to MySQL and PostgreSQL servers which all are working fine. The timeout happens when connecting from both macOS dev laptop and Debian python:3.8-slim-buster Docker image that we use in production.

ODBC driver is installed by

RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
    apt update && \
    ACCEPT_EULA=Y apt install -y msodbcsql17

On macOS the driver is installed by

brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew install msodbcsql17 mssql-tools

The error message is

[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)

Modifying timeout value does not help. The connection happens instantly when connecting directly.

Any idea why it fails for proxy?

Thanks,

Andrei


Linked Server to Oracle does not work for all logins.

$
0
0

HI . 

I am getting ORA-12514 while accessing Oracle from SQL Server .
It works with Windows Authentication ; but the same query does not work with SQL authentication . 

I configured linked server with "Be made using this security context" as shown below.



Here , ORA_DWCS is the linked server , NCDB is the oracle schema and CLIENT is the oracle table. 


C:\>sqlcmd -W -S sql02,4630
1>  Select  count(*)  from ORA_DWCS..[NCDB].[CLIENT];
2> go

-
6625

(1 rows affected)
1> exit

C:\>sqlcmd -U oracleusertg -P oracleusertgpassword -S sql02,4630
1>  Select  count(*)  from ORA_DWCS..[NCDB].[CLIENT];
2> go
Msg 7303, Level 16, State 1, Server SQL02, Line 1
Cannot initialize the data source object of OLE DB provider "OraOLEDB.Oracle" for linked server "ORA_DWCS".
OLE DB provider "OraOLEDB.Oracle" for linked server "ORA_DWCS" returned message "Error while trying to retrieve text for error ORA-12154".
1> exit

C:\>


Thanks in Advance

Windows 10 integrated email user login Message=Cannot open database requested by the login.

$
0
0

Im new to win 10 and just got a new laptop.  I installed SQL server express and created a database with windows authentication.

In visual studio I added the server and copied the connection string but i am getting the error:

System.Data.SqlClient.SqlException
  HResult=0x80131904
  Message=Cannot open database "x" requested by the login. The login failed.
Login failed for user 'MicrosoftAccount\me@live.com'.
  Source=.Net SqlClient Data Provider
  StackTrace:
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   at X.StdyDataSetTableAdapters.XTableAdapter.Fill(XDataTable dataTable) in C:\Users\me\Desktop\X\X\StdyDataSet.Designer.cs:line 929
   at X.Form1.LoadData(String pw) in C:\Users\me\Desktop\X\X\Form1.cs:line 48
   at X.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\me\Desktop\X\X\Form1.cs:line 35
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


McC


ADODB Connection to Azure Database changing to 'master' instead of targeted Database

$
0
0

Attempting to connect to new Azure Database using ADODB method from Access. 

Using ODBC native client 11 Access is able to connect to tables via Link Tables

In script, attempting to connect using ADODB script. Using the following connection string I am able to connect to the database, but an error is logged on the cnn object.

     [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Changed database context to 'master'.

The connection string I am using:

    sConnectionString = "Driver={SQL Server Native Client 11.0};" & _
                        "Server=tcp:###.database.windows.net,1433;" & _
                        "Initial Catalog=###;" & _
                        "Persist Security Info=False;" & _
                        "Uid=###@###;" & _
                        "Pwd={###};" & _
                        "Database='###';" & _
                        "Encrypt=yes;Connection Timeout=30;"

### used to redact info

I have also tried to set the "Current Catalog" value directly after the connection is established.

   cnn.Properties.Item(0).Value ="aglia@agliadb"

Error message reads

   "Property Value is Invalid. Make sure the value is typed correctly"

Sum 2 weeks of sales starting at first sale that is on or after specific date

$
0
0

I wrote the following query which pulls sales units for the first 2 weeks the inventory has been in stock. My company uses a SQL Server database.

I want it to sum the first 2 weeks of sales starting from the first date of sale that has a Quantity greater than 0 that took place on or after the FirstReceiptDate.

The caveat is that I can't just sum from the first date of sale because we have people that make mistakes and process a transaction prior to inventory even being here, messing it all up. It needs to factor bot of those criteria.

SELECT
    CAST(SUM(TPE.Quantity)/3 AS Int) AS 'SaleUnits',
    CAST(I.[ItemCode] AS Int) AS SKU,
    I.[ItemName] AS 'Item Name',
    CAST(I.[FirstReceiptDate] AS DATE) AS 'FIRSTRECEIPT'
FROM
    [Comp].[vTransSales] AS TPE
INNER JOIN 
    [Comp].[vSalesData] AS I ON CAST(TPE.[Item No_] AS INT) = CAST(I.[ItemCode] AS INT)
INNER JOIN 
    [Comp].[vTime] AS T ON CAST(TPE.[Date] AS DATE) = CAST(T.[Date] AS DATE)
INNER JOIN
    [Comp].[vItemDivision] AS ID ON I.[DivisionCode] = ID.Code
WHERE 
    CAST(TPE.Date AS DATE) BETWEEN CAST(I.[FirstReceiptDate] AS DATE) 
                               AND DATEADD(DAY, 13, CAST(I.[FirstReceiptDate] AS DATE))
    AND [I].[DivisionCode] IN ('550')
GROUP BY
    CAST(I.[ItemCode] AS INT), I.[ItemName], I.[FirstReceiptDate], CAST(TPE.[Item No_] AS INT), ID.[Code], I.[DivisionCode]

I want the end result to look like the following.

Example

Further still, I would like to add another column that would do 4 weeks, but wanted to take it a step at a time.

Azure Data Studio

$
0
0

Hi everybody,

I've been using SSMS to work with Azure SQL Databases. Yitzhak just told me about Azure Data Studio and I found a link to download but no real description at that link.

If someone here is using it, can you please tell me in brief what are the benefits of installing and using it and what features does it provide SSMS does not? 

Thanks a lot in advance.


For every expert, there is an equal and opposite expert. - Becker's Law


My blog


My TechNet articles

ERROR [IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application

$
0
0

Hi All,

When I try to connect MySQL database through SSIS I am getting this error "ERROR [IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application".

I have successfully installed MYSQL ODBC driver 64 bit, OS is 64 bit and SSDT 2015 is also 64 bit. But still I don't know why i am getting this error. I have gone through many blogs but unable to fix it. 

Tried to change the platform in connection manager but unable to do it. As I click on NEW under active platform drop down it is not opening new window for me.

Can anyone help me to fix this issue.

Thanks all in advance.

Regards,

Naga

ODBC disappearing drivers

$
0
0

hello,

i builded up an odbc system between my company database and a third software for manage di item label printers, everything was working well after a week the system was not working anymore for all the users except me, i tried in the odbc admin tool to delete the ridondant rules made testing the system keeping the main one and now is not working anymore also in mine account...the error message says something about a mismatch between the odbc drivers... if i can provide more infos about let me know... Thanks 


Viewing all 4164 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>