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

Understanding the masterDB -- would be it be able to tell me when user login attempts fail?

$
0
0
I don't quite understand the masterdb. The documentation online says it will store "user login" but what does that mean? When a user logs in, will it store info such as whether or not it was a successful login? 

Delete and insert in transaction. Select returns not all records.

$
0
0

Hello,

Recently I have found some very interesting situation. It seems like a bug. 


I have table:

            CREATE TABLE [dbo].[_TestTable](
                  [ID] [uniqueidentifier] NOT NULL,
                  [DataID] [uniqueidentifier] NOT NULL,
                  [Value1] [varchar](50) NOT NULL,
                  [Value2] [varchar](50) NOT NULL,
             CONSTRAINT [PK__TestTable] PRIMARY KEY CLUSTERED 
            (
                    [ID] ASC
            )  ON [PRIMARY]
            ) ON [PRIMARY]

And .NET code witch do the following:

            var cn = new SqlConnection();
            cn.ConnectionString = "Server=myserver;Database=mydatabase;User Id=myuser;Password=mypass";
            cn.Open();

            while (true)
            {
                var dataId = new Guid("53767E35-57B1-4729-9363-D14C2BC5D9AE");

                using (var tr = cn.BeginTransaction())
                {
                    var cmd = new SqlCommand($"delete from _TestTable WHERE DataID = '{dataId}'", cn, tr);
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();

                    for (var i = 0; i < 10; i++)
                    {
                        var sqlQuery = $"insert into _TestTable(ID, DataID, Value1, Value2) values(newid(), '{dataId}', 'Some value 1 - {i}', 'Some value 2 - {i}')";
                        cmd = new SqlCommand(sqlQuery, cn, tr);
                        cmd.ExecuteNonQuery();
                        cmd.Dispose();
                    }

                    tr.Commit();
                }
            }

Then I open SSMS and execute the simple query 

select * from _TestTable

In most cases I get 10 records. But sometimes I get 9, 8 or 7 records.

Linked server error. Oracle from SQL Server

$
0
0

Hi,

I am trying to access Oracle database from SQL Server.
I installed ODAC also in source machine.
Created the Linked server in SQL Server Source server below.

Exec sp_addlinkedserver 'Test',Oracle,'OraOLEDB.Oracle','Oracedbservername:Port/OracleDB'

In Test Properties : Server Objects: I checked The "Use Remote Collection" to True.

Security : selected "Be made using this security context: Gave Remote login and password.

When i am testing the connection getting the error con not create n instance of OLEDB provider 'OraOLEDB.Oracle' for inked server "Test".(error:7302)

Please help me to resolve the issue. Its urgent.

Thanks,


pols

Query regarding Oracle Live SQL tool

$
0
0

Hi dear friends,

My query is like can we run Oracle Live SQL tool through command line  Prompt?

so we can run programs which takes inputs from user ?

Please answer this. and if yes then tell the procedure.

Oracle Live SQL tool ink (https://livesql.oracle.com/apex/f?p=590:1:14307109672480::NO:RP::#)

Please ans it..

Thanks..



A transport-level error has occurred when receiving results from the server.(provider:TCP Provider,error:0-The handle is invalid

$
0
0

Hi,

I am using SQL Server 2005,

while trying to retrieve data from the database; I am getting the following error:

 A transport-level error has occurred when receiving results from the server. (Provider: TCP Provider, error: 0 - The handle is invalid.)

 But I am getting this error randomly.

 Can some one help me out?
 Waiting for your response

 Sudhakar

SqlBulkCopy Failed

$
0
0

Hi folks, I'm receiving an error when running SqlBulkCopy, sometime it fails and other times it runs ok, error message below;

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParserStateObject.WriteSni(Boolean canAccumulate) at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate) at System.Data.SqlClient.TdsParserStateObject.WriteByteArray(Byte[] b, Int32 len, Int32 offsetBuffer, Boolean canAccumulate, TaskCompletionSource`1 completion) at System.Data.SqlClient.TdsParser.WriteString(String s, Int32 length, Int32 offset, TdsParserStateObject stateObj, Boolean canAccumulate) at System.Data.SqlClient.TdsParser.WriteUnterminatedValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj, Int32 paramSize, Boolean isDataFeed) at System.Data.SqlClient.TdsParser.WriteBulkCopyValue(Object value, SqlMetaDataPriv metadata, TdsParserStateObject stateObj, Boolean isSqlType, Boolean isDataFeed, Boolean isNull) at System.Data.SqlClient.SqlBulkCopy.ReadWriteColumnValueAsync(Int32 col) at System.Data.SqlClient.SqlBulkCopy.CopyColumnsAsync(Int32 col, TaskCompletionSource`1 source) at System.Data.SqlClient.SqlBulkCopy.CopyRowsAsync(Int32 rowsSoFar, Int32 totalRows, CancellationToken cts, TaskCompletionSource`1 source) at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsyncContinued(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source) at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsync(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source) at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet internalResults, CancellationToken cts, TaskCompletionSource`1 source) at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletionSource`1 source) at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalAsync(CancellationToken ctoken) at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32 columnCount, CancellationToken ctoken) at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table, DataRowState rowState) at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table) at Tyrescanner_Import_Service.Program.InsertDataIntoSQLServerUsingSQLBulkCopy(DataTable csvFileData, String tempCSV_file_path) ClientConnectionId:d6768079-0ddd-4bf6-95a9-ce155d852d00 Error Number:-2,State:0,Class:11

MSOLEDBSQL connection string with MultiSubnetFailover=true

$
0
0

Hi All,

Can some one help me with MSOLEDBSQL connection string with MultiSubnetFailover=true.

How can i create MSOLEDBSQL  linked server with MultiSubnetFailover=true.

Help will be much appreciated and thanks in advance.

Padmakumar

 

Giving dynamic sheet name while importing data from Excel in OPENROWSET query

$
0
0
I want to import data from Excel to table in SQL server. Sheets in Excel file can have any name. I want to get data from first sheet of the excel file. 
CREATE PROC CopyExcelDataToTempTable
@ExcelPath VARCHAR(1000)
AS
BEGIN
	EXEC sp_configure 'show advanced options', 1;
	RECONFIGURE;
	EXEC sp_configure 'ad hoc distributed queries', 1;
	RECONFIGURE;

	EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1;
	EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1;

	INSERT  INTO TempData
		SELECT *
		FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
		SELECT CONCAT('Excel 12.0 Xml;HDR=YES;Database=', @ExcelPath),
		'SELECT * FROM [Sheet1$]');
END;
Currently I am giving Sheet1 as static name in Select statement. But my sheet name is not fixed. I want to create a dynamic query. If getting Sheet name is not possible then can we put sheet with its index in Select query? There is no front end. Whatever I want to do is in SQL server 2012. Is there any solution for this problem?

SQL Server 2014 Linked Server error

$
0
0

The linked server is a SAGE 100 database (MAS90). It has been working for a year. The remote server was moved to a new location. Same server, but new IP address. The OBDC DSN tests successful. But any attempt to get the linked server to work results in Error 7303

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "SAGEDATA".
OLE DB provider "MSDASQL" for linked server "SAGEDATA" returned message "[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed".
OLE DB provider "MSDASQL" for linked server "SAGEDATA" returned message "[ProvideX][ODBC Driver][ISAM]ISAM communication error". (Microsoft SQL Server, Error: 7303)

-----------------------------

MSDTC Failure - Enlist operation failed: 0x8004d01c(XACT_E_CONNECTION_DOWN).

$
0
0

Hi,

We had to recycle MSDTC for some other reason and noticed that all transactions started failing with the below error.

Enlist operation failed: 0x8004d01c(XACT_E_CONNECTION_DOWN). SQL Server could not register with Microsoft Distributed Transaction Coordinator (MS DTC) as a resource manager for this transaction. The transaction may have been stopped by the client or the resource manager.

All these transactions were going through fine until we recycled the dtc service. We noticed in some forums that the only solution is to restart sql server service.

Curious to know -

  • What is the sql server registration process with MSDTC and what could cause this to fail?
  • Any other resolution other restarting the services ?
  • Any proactive measures to avoid this failure?


Trinity

Uncommittable transaction when testing connectivity to (offline) linked server

$
0
0

Issue: when testing connectivity to an offline linked server wrapped inside a transaction, my transaction becomes uncommittable. However, I still need to execute the remaining code in the stored procedure. I am using sys.sp_testlinkedserver for testing connectivity. How to get around this issue?

Background:

I have two servers: ServerA and ServerB. Both are running SQL Server 2016. On ServerA I have a production database, and on ServerB I have a Historian database.

ServerA has a Linked Server object HISTORIAN which points to ServerB (using SQL User authentication) and has the default server options, except Collation Compatible which is set to True. Provider: SQL Server Native Client 11.0.

On ServerA a stored procedure sp_A1 is executed which starts a production order. This stored procedure calls another stored procedure sp_A2 that queries the Linked Server via the four-part name syntax, which queries certain Historian data and stores this on the production database with the started order.

Goal: if the Historian is not accessible (wrong user, server offline, MSSQLSERVER service not running) I still want to start the production order (we just don't store the Historian values in the production database).

Constraints: sp_A1 is always wrapped in a transaction, because of the way the user application connects to SQL Server on ServerA. I cannot change this, but I can change the stored procedures itself and SQL Server configuration. I cannot separate the calls to sp_A1 and sp_A2, meaning all the work that needs to be done needs to be initiated by a single stored procedure.

Example:

As a simple example I have created the excerpt below. Referring to the background discussed above, everything inside the BEGIN/COMMIT TRANSACTION would be sp_A1. And everything between the first and last SELECT statement would be sp_A2.

BEGIN TRANSACTION

    SELECT'execute some code...'

  DECLARE@return_codeINT

  DECLARE@sSQLNVARCHAR(MAX)

  --Use try and catch to test whether the Historian is accessible through linked server

  BEGINTRY

    PRINT('Testing connection with the linked server.')

    -- Tests the connection to a linked server. If the test is unsuccessful the procedure raises an exception with the reason of the failure.

    EXECsys.sp_testlinkedserverHISTORIAN

  ENDTRY

  BEGINCATCH

    PRINT('Error with accessing Historian, error_code = -5')

    SELECT@return_code=-5;

  ENDCATCH

  SELECT@return_code

  IF@return_code<>-5

  BEGIN

    SET@sSQL='SELECT value1,value2 FROM HISTORIAN.Runtime.dbo.History WHERE order_id = ''12345678'''

    EXECSP_EXECUTESQL@sSQL

  END

  SELECTXACT_STATE()

  SELECT'execute some more code...'

COMMIT TRANSACTION

Note that dynamic SQL is used to prevent syntax checking for the Linked Server on creation of the stored procedure (in cases where the linked server object has not yet been created, or when ServerB is not yet installed).

What I find is that when I execute this code without BEGIN/COMMIT TRANSACTION (and my Linked Server is unreachable), no error is thrown. But, when including the BEGIN/COMMIT TRANSACTION statements, the transaction becomes uncommittable. From what I understand is that this means SAVEPOINTS do not help here. The issue is that I have no way around the BEGIN/COMMIT TRANSACTION statements (see Constraints).

Is there a way around this? Or an alternative method to access the database on ServerB from a stored procedure on ServerA?

Thanks for your help and thoughts.

Connection string for new OLE DB Driver 18 for SQL Server

$
0
0

I have SQL Server 2019 CTP 3.0. I need to connect to it from Excel VBA through ADODB library with new OLE DB 18 driver. How connection should look like to use this new driver? I have found something like this:

Provider=MSOLEDBSQL;DataTypeCompatibility=80

Will this pickup new driver? Is DataTypeCompatibility necessary?


There is no knowledge that is not power.

JDBC driver for SQL Server working with Java program

$
0
0

I downloaded latest JDBC driver, but when I run my Java program I keep getting an error that the JDBC driver can't be found.

What is the proper wording of the driver?  I used what the documentation at MSFT site says and is creating the error.

I'm trying to connect to my SQL database try Java program.  


How to run .dtx job that query from another database and dumps it on a network drive?

$
0
0

If I execute the .dtx package it executes fine; however, when I try to start a job it failed. The job is setup to "Run as" a Proxy user that has DataRead access on the other database (db12\reports). The error is something like this:

05/23/2019 13:39:43,Proxyuser - myApp,Error,,DB11,Proxyuser - myApp,,,The job failed.  The Job was invoked by User myDomain\MyUserName.  The last step to run was step 1 ( threat table CSV dump).,00:00:00,0,0,,,,0
05/23/2019 13:39:43,Proxyuser - myApp,Error,1,DB11,Proxyuser - myApp, threat table CSV dump,,Executed as user: myDomain\myApp. Microsoft (R) SQL Server Execute Package Utility  Version 12.0.6259.0 for 64-bit  Copyright (C) Microsoft Corporation. All rights reserved. 

Do I need to link the server (db12/reports) to this DB11 for the job to run?

<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} </style>

How to set up “log on” to the SQL Server running on my computer.

$
0
0

Because of the corruption of the personal account I have been using, I can no longer access to my SQL Server using “Window Authentication.” Therefore, I should like to set up a new “log on” as a Microsoft administrator using SQL Server Configuration Manager. As I display the menu of the running Server, I see the “Local System” checked.  I also see the “This Account” unchecked with the login name box and the password box. How can I set up the new “Window Authentication” from the Microsoft administrator account? In case this is not possible, how can I set up “SQL Server Authentication” with this menu? Please instruct me. Thank you.


tatsuo nishimura manabe


SQL Server Native Client driver change

$
0
0

Hi,

We have upgraded SQL Server 2008 to 2017 version. There are some application which are facing slowness after up-gradation. Application is using linked server. We found the linked server which are using below driver are facing slowness. 

1) SQL Server Native Client 10.0

2) Microsoft OLE DB Provider for SQL Server

We want to change the linked server driver to following-

3)  Microsoft OLE DB Provider for ODBC Driver

Please let me know if there is any chance of dataformatting change/value change/truncating after the driver change?

Regards

Arif


Azure API authenticate to SQL Server

$
0
0

Hi,

I am trying to add row level security to my SQL Server on Azure. I have an API that authenticated users send their token to to gain access.

What I am trying to do is now use the authentication from the Azure AD to control access to rows in a table.

Does anyone have any documentation to get me to this point? I'm not sure how I link the Authentication token given to the API to access the SQL Server.

THanks.

Redirect Queries

$
0
0

Hello,

I have an MVC application when I used one model. Then we transfer a part of this model(4 tables) to another database.

How can i use this database, without add another model on my application?

Thank you

SqlConnection.GetSchema() Throws Exception in Release Build

$
0
0

In a UWP app, SqlConnection.GetSchema(string, string[] args) will throw an "ArgumentNull" exception in a release build, with or without code optimization. Same exact GetSchema() call works fine in debug builds. I can also otherwise successfully connect and query the server (a remote machine). Tried SQL Server versions 2012 & 2017.

Specific Exception is a System.AggregateException, with an Inner Exception of ArgumentNull: "value cannot be null. Parameter name: xmlStream."

Using Visual Studio 16.1.5 and Microsoft.NETCore.UniversalWindowsPlatform 6.2.8

Stack trace:

at System.Data.ProviderBase.DbMetaDataFactory..ctor(Stream xmlStream, String serverVersion, String normalizedServerVersion)
at System.Data.SqlClient.SqlConnectionFactory.CreateMetaDataFactory(DbConnectionInternal internalConnection, Boolean& cacheMetaDataFactory)
at System.Data.ProviderBase.DbConnectionFactory.GetMetaDataFactory(DbConnectionPoolGroup connectionPoolGroup, DbConnectionInternal internalConnection)
at System.Data.ProviderBase.DbConnectionInternal.GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, String collectionName, String[] restrictions)
at System.Data.SqlClient.SqlConnection.GetSchema(String collectionName, String[] restrictionValues)
at System.Data.SqlClient.SqlConnection.GetSchema(String collectionName)
at AklauSimpleQueryUWP.Data.CrudSQL.GetSchemaTables(DataTable& pDataTable) in D:\Users\ricci\Documenti\Visual Studio 2019\Projects\Aklau_Simple_Query_UWP\Data\CrudSQL.cs:line 119


eidon

MSDTC errors after server rename

$
0
0

Renamed a server (Windows Server 2016 Standard) with an existing SQL Server 2016 instance on it.  Checked @@SERVERNAME to ensure the name is correct.  However, when SSIS packages are run (from SSISDB) with supported transactions, getting the following error:

The SSIS Runtime has failed to enlist the OLE DB connection in a distributed transaction with error 0x8004D00E "The transaction has already been implicitly or explicitly committed or aborted"

Checked DTC services, settings, permissions.  Even uninstalled and reinstalled DTC.

Any assistance is greatly appreciated.  

Viewing all 4164 articles
Browse latest View live


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