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

Troubleshooting intermittent connection issue to SQL Server 2016

$
0
0

Hi

We have facing a strange intermittent connection issue to one of our SQL Server 2016, on app server side from time to time we are receiving the error:
A network-related or instance-specific error occurred while establishing connection to SQL Server, the server was not found ..

I am facing the same intermittent issue with a small .net tool we created that test a connection to SQL server using a connection string as a param, we know that this is not a DNS resolution issue since we are facing the issue using the IP adr too, the strange thing is we are not able to reproduce the issue using UDL file, SQLCMD tool or from the ODBC test connection form

Some componenets of the application are using ODBC and others JDBC and I have updated all JDBC, ODBC, Native clients drivers

No errors in SQL server or windows logs, the only thing that our admin can see is this error they captured using netsh tool:
Create, Status: Status Access denied, filename: sql\query

I have read most of threads and articles I can find related to communication issue with SQL Server and nothing is applying to our case


Environnement:
App server : Windows Server 2016 .net 4.5
SQL Server : Windows Server 2016 .net 4.5 + SQL 2016 SP2

Any feedback on how to resolve this issue ?

Best regards

  

Mohamed B.




Restoring Contoso Back file failed-Backup and restore errors: the file specified in Restore command is damaged or is not an AS backup file.

$
0
0

Hi

I downloded and extracted Contoso file as explained in this link:

https://www.microsoft.com/en-ca/download/details.aspx?id=18279

but I kept receiving the following error:

Backup and restore errors: File '...\ContosoDataSet\ContosoBIdemoABF\Contoso_Retail.abf' specified in Restore command is damaged or is not an AS backup file.
The following system error occurred:  Access is denied.  (Microsoft SQL Server 2017 Analysis Services)

What is the reason and what is the workaround?

Thanks

About insert datetime into database.

$
0
0

Hi all

I try to insert the datetime into the database by ODBC, the data can be insert into the data base but the second and millisecond has missing, (for example :2019-4-15 15:35:00.000) , and the sqlstate is 01004, but there is no problem when I use sqlserer 2012 and 2014.

I also write the example to test it ,but get some problem when the code go to the SQLExecDirect (SQLstate 42000), here is the code:

   SQLHENV *hEnv = NULL; // ODBC Environment Handle
SQLHANDLE *hDbc = NULL; // ODBC Connection Handle
SQLHANDLE *hStmt = NULL; // ODBC Statement Handle

/*
** Connection Information
*/

TCHAR *dsn = _T("test1");
TCHAR *uid = _T("TestUser");
TCHAR *pwd = _T("P@ssw0rd");
TCHAR *szSelect = _T("INSERT INTO dbo.Table_1(time1) VALUES(?)");

TCHAR *pParameterArray = _T("{ts '2018-07-13 13:32:57.632'}");


SQLRETURN rc;


/*
** Allocate handles
*/
rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, (SQLHANDLE *)&hEnv);

rc = SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);

rc = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, (SQLHANDLE *)&hDbc);

/*
** Connect to the database
*/
rc = SQLConnect(hDbc, dsn, (SQLSMALLINT)_tcslen(dsn),
uid, (SQLSMALLINT)_tcslen(uid),
pwd, (SQLSMALLINT)_tcslen(pwd));

SQLWCHAR       SqlState[6], SQLStmt[100], Msg[SQL_MAX_MESSAGE_LENGTH];
SQLINTEGER    NativeError;
SQLSMALLINT   i, MsgLen;
SQLRETURN     rc1, rc2;
SQLHSTMT      hstmt;
SDWORD nSQLErrorCode;
SWORD nMsgSize;



if ((rc == SQL_SUCCESS_WITH_INFO) || (rc == SQL_ERROR)) {
SQLLEN numRecs = 0;
SQLGetDiagField(SQL_HANDLE_STMT, hDbc, 0, SQL_DIAG_NUMBER, &numRecs, 0, 0);
// Get the status records.

int nError = SQLError(hEnv,
hDbc,
hStmt,
SqlState,
&nSQLErrorCode,
Msg, sizeof(Msg),
&nMsgSize);


i = 1;
while (i <= numRecs && (rc2 = SQLGetDiagRec(SQL_HANDLE_STMT, hDbc, i, SqlState, &NativeError,
Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA) {
//DisplayError(SqlState, NativeError, Msg, MsgLen);
i++;
}
}
/*
** Allocate the statement handle
*/
rc = SQLAllocHandle(SQL_HANDLE_STMT, hDbc, (SQLHANDLE *)&hStmt);

//// Step 1: Prepare
//rc = SQLPrepare(hStmt, szSelect, SQL_NTS); // select
#if 1
rc = SQLBindParameter(hStmt,
1,/* ipar: Param number, start at 1 */
SQL_PARAM_INPUT,/* fParamType: SQL_PARAM_INPUT, ... */
SQL_C_TCHAR, /* fCType: SQL_C_FLOAT, ... */
SQL_C_TIMESTAMP,/* fSqlType: SQL_FLOAT, ... */
19,/* cbColDef: precision, ... */
3,/* ibScale: ... */
pParameterArray,/* rgbValue: pointer to data buffer */
128,/* cbValueMax:  64*/
NULL/* pcbValue: Return length, SQL_NTS, SQL_NULL_DATA  NULL*/
);
#endif

if (rc != 0)
{

SQLTCHAR MessageText[256];
SQLTCHAR SqlState[5 + 1];
SQLINTEGER NativeError;
SQLSMALLINT TextLength;
SQLRETURN sts = SQL_SUCCESS;

rc = SQLGetDiagRec(SQL_HANDLE_STMT, hStmt, 1, SqlState, &NativeError,
(SQLTCHAR *)&MessageText, sizeof(MessageText),
&TextLength);

AfxMessageBox(MessageText);
}
rc = SQLExecDirect(hStmt,szSelect,_tcslen(szSelect)*sizeof(TCHAR));

MDF and LDF Files in a different location

$
0
0

Hello all,

I would like to know if its possible to keep the database files in another drive while the installation of the SQL Server engine is in another disk. Can i do that with a NAS device? a  USB external disk? 

Thanks in advance!

error 22008: Datetime field overflow when inserting a record with datetime2 field via ODBC

$
0
0

I have a simple table with a datetime2 field CreatedOn. When I execute the following code

an exception with error code 22008 is raised.

 

OdbcCommand cmnd = new OdbcCommand

    (@"INSERT INTO VERSIONINFO (Version, CreatedOn) VALUES (?, ?)", dbCon);
cmnd.Parameters.Add(new OdbcParameter("", "1"));
cmnd.Parameters.Add(new OdbcParameter("", DateTime.Now));
cmnd.ExecuteNonQuery();

The same code worked well with the SQLServer 2005 and the appropriate native client. I have to round the DateTime parameter to the nearest second in order to make this code work. That indicates a problem in the OdbcParameter implementation which should do the rounding required.

 

Is this a bug in June CTP?

 

Thanks,

Dejan

 

Creating a link server from an odbc DSN

$
0
0

Hi everyone,

I need to create a linked server to an oracle server.  I have tried creating the link server with the odbc DSN for which the connection test ok and from the oracle Provider for OLE DB.

I the case of the ODBC attempt I get an authentification failure error 7399 even after inputing the UserName and Password in the security tab of the LinkedServer configuration using the 4th option (Be made using this security context).

In the case of the oracle connection I get an error ORA-12154 which is essentially saying it is not finding the TSNNAMES.ora service.  I can connect with sqlPlus, sql Developper and with ODBC 64bit driver.

I have been at it for hours and need a pro.

tks


Visual Studio 2008 project

$
0
0

I have an old visual studio .sln and my PC was reset (PC Reset) about a year ago and I lost a lot of files. But my solution is still here. Problem is when I tried to reinstall sql express, it stated it may not run well with windows 10. So I stumbled onto the Sql server 2017 which I downloaded. Now my project will no longer show my database and I can't see how to connect the new sql to my old website.

Do I have to just scrub my old website because it was built with old software? I need to update it but cannot deploy it now until I make sure its running correctly.

SQL hide All sys objects from User access - give user access only to specific objects from dbo schema and all objects within Test schema

$
0
0

We have an application that we need to restrict access to. The application will be using login TestApp. I've been testing this under Sql Server Management Studio v 17.9.1 and we are using SQL Server 2016. This Login will have access to all tables Store procs, views , functions and triggers within its own schema Test in Database: Testing, and only to certain tables from dbo Schema that we specify in the permissions of the TestAPP user. I've used the following script to achieve that. The problem we are having is that the Login can access all System Views and Store Procs and we don't want this level of access. This login Shouldn't be able to do those under schema TEST.

1) Create, drop, alter tables from Test schema

2) Create, alter, drop views from Test schema

3) create , alter , drop store procs from Test Schema.

We are trying to use Roles so that we don't have to specify each and every sys object that we want to deny access to.

I've created the Role [db_TestExecutor] and attached the role to the user. and then gave specific permissions for the dbo tables but still they can see all sys objects.

Used SQL code Below:

USE[Testing]
GOCREATESCHEMA[Test]AUTHORIZATION[dbo]

GO

CREATE ROLE [db_TestExecutor]
GOGRANTEXECUTEONSCHEMA::Test TO[db_TestExecutor]
GOGRANTSELECT,INSERT,UPDATE,DELETEONSCHEMA::Test TO[db_TestExecutor]USE[mASTER]
GOIFNOTEXISTS(SELECT1FROM sys.server_principals WHERE[name]='TestApp')BEGINCREATE LOGIN TestApp WITH PASSWORD=N'Password123', DEFAULT_DATABASE=[tempdb], DEFAULT_LANGUAGE=[British], CHECK_EXPIRATION=OFF, CHECK_POLICY=ONENDUSE[Testing]
GOCREATEUSER[TestApp]FOR LOGIN [TestApp]
GOALTER ROLE [db_TestExecutor]ADD MEMBER  [TestApp]
GOGRANTINSERTON[dbo].[tblOrders]TO[TestApp]
GO              GRANTSELECTON[dbo].[tblOrders]TO[TestApp]
GO              GRANTUPDATEON[dbo].[tblOrders]TO[TestApp]
GOGRANTSELECTON[dbo].[test]TO[TestApp]

I expect the TestApp login to be able to see only objects from Test schema and only certain dbo tables.


connect retry count and connect retry interval in SQL connection string

$
0
0

Hi

In ODBC connection config form there is a way to set a connect retry count and a connect retry interval, we are wondering if there is a way to implement a connection retry in .net/sql connection string without changing the code of the application and implement a system retry manually? Seems those two properties are missing from the connection string and from the .net connection builder class!

Best regards


Mohamed B.

Installing odbc 17.3.1.1 throws an error: "There is a problem with this Windows installer package. A DLL required for this install to complete could not be run" on Windows 2016 systems

$
0
0
I am trying to install the latest version of SqlCmd from here https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-2017 and in the process of installing its prerequisite odbc packages on Windows 2016, I am getting an error message that "There is a problem with this Windows installer package. A DLL required for this install to complete could not be run". I could not find any pre-requisites for these ODBC installers here (https://www.microsoft.com/en-us/download/details.aspx?id=56567). Perhaps there's a reference to a specific VCredist version? Has anybody encountered this issue before? Thank you.

How to remove Table (Heap) Fragmentation

$
0
0

I used below query to find Table (Heap) & Index fragmentation. How can I remove Table (Heap) Fragmentation?

SELECT dbschemas.[name] as 'Schema',
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
 indexstats.index_type_desc as 'Heap/Index Type',
indexstats.avg_fragmentation_in_percent as 'Fragmentation %',
indexstats.page_count,
indexstats.forwarded_record_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS indexstats
INNER JOIN sys.tables dbtables on dbtables.[object_id] = indexstats.[object_id]
INNER JOIN sys.schemas dbschemas on dbtables.[schema_id] = dbschemas.[schema_id]
INNER JOIN sys.indexes AS dbindexes ON dbindexes.[object_id] = indexstats.[object_id]
AND indexstats.index_id = dbindexes.index_id
WHERE indexstats.database_id = DB_ID()
ORDER BY indexstats.avg_fragmentation_in_percent desc;

Second call to ODBC call to Microsoft Access fails after upgrade from Office 2010 to 2016

$
0
0

After upgrading from Office Professional 2010 to 2016, the first ODBC call the Access is successful.  However, the second and subsequent calls fail.  We are calling from an SQL database via a third party vendor (Intact by Infodynamics).  They have not been able to help.  Log is below.  Any ideas?

The database is on the network and is an accdb file 

32 bit ODBC driver being used on the Windows 10 local machines is 16.00.4684.1000  Microsoft Access Driver (*.mdb, *.accdb).  There are 10 machines and it  happens on all of them with any user, including an administrator.

SQL version of the database on the Windows Server 2012 server is 11.9.2100

Nothing changed except for the upgrade to Office 2016 which is version 16.0.4738.1000


Waiting for ole db resource and cannot Kill Process in KILLED/ROLLBACK

$
0
0

I have a query to refer to the data source in as400 with ODBC 'iSeries Access for Windows ODBC data source' and a linked server with 'oledb for ODBC driver' in SQL2005 (9.0.2047)

Now we got 2 problems,

1.  When we refer to the view with openquery e.g select * from openquery (abc, 'select * from dates')

This query continue to run without ending.  In Activity monitor, we found that it is waiting for resource ole db

2.  Since the process continue to run without ending, I kill the process in activity monitor or by command 'kill'.  It shows the status 'KILLED/ROLLBACK' and it returns 'SPID 197: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds.' in 'kill 197 with STATUSONLY'

 

In problem 1, I found some ppl encountered the same problem (waiting for resource oledb) with openquery to different data source e.g. vfp, oracle. 

In problem 2, we can't restart the sql server for clear the unkillable process

Kindly advise.  Thanks in advance.

 

 

 

 

 

Inserting a string with apostrophe to SQL Server

$
0
0
Hi,

I develop a windows application using C#. I try to take a value from the textbox and put it in the table on SQL server. I create a connection string and the command string (ODBC). The value I want to insert surrounded with apostrophes. The problem occurs when user wants to insert apostrophe in the textbox. It is inserted to the string value and SQL server recognizes it as an end of string.
Does anybody know how to resolve this problem?

thank you.

Query Execution plans - Tuning suggestion

$
0
0

Could you please go through the queries and its execution plan with all the cost and metrics

and suggest tuning recommendations on query rewrite and index changes etc to reduce the cost and better the performance (or) does they look fine and no changes are needed.

can you brief a bit on the cost from the plans [ say - index scan 79% in query plan 4 , is that fine... and on estimated no.of rows and actual execution, sub-tree cost etc how do we draw out the conclusions based on these metrics] for my understanding

(1)

https://www.brentozar.com/pastetheplan/?id=rJdp6DsqN

(2)

https://www.brentozar.com/pastetheplan/?id=HJYhlds94

(3)

https://www.brentozar.com/pastetheplan/?id=r1nS2Q3qE

(4)

https://www.brentozar.com/pastetheplan/?id=r1JG6m3qV


Thanks a lot.


Kenny ShareNlearn



Differences with Special Characters in SQL Server 2008 vs SQL Server 2016

$
0
0

Just wondering can anyone explain the difference between SQL Server 2008 and SQL Server 2016 in terms of running query with special characters. I'm getting totally different results when running this query in 2008 vs 2016.  

For example:

Value(s)


select tx_title
from source
where contains((tx_title), '"Value(s)"')





Hi - ports needed to connect a client on domain A to a sql named instance (using 8010) on domain b

$
0
0

Hi,

What ports need to be open to connect a client (eg MS Access on Win 10) on domain A to a sql named instance (using 8010) on domain b?

Is the answer:

8010 &

1434 UDP

OR is it:

8010 &

1434 UDP &

1433 TCP

?

OR something else?

thanks!

How to Connect to Sybase from MSSQL (liked server)

$
0
0

Hi,

try my column, it should be helpful for those who has troubles to connect in.

Ondrej

https://www.sqlservercentral.com/?p=3539271&post_type=ssc_article&preview_id=3539271

Connect / import jpg from file share

$
0
0

Hi,

I need to connect / import jpg image from a file share to an SQL DB.

It' possible?

Can anyone explaine me the procedure?

Thanks!

Regards

Faye

the row_number command slowed down my database, someone would have a way to optimize the speed

$
0
0
SELECT *

FROM
( SELECT * , ROW_NUMBER() OVER(PARTITION BY [Matricule] ORDER BY [Matricule] ASC, [Matricule] DESC) AS RowNumber
 
FROM 
[Name view] 

WHERE 
[Usine] Like 'usinename' AND ([DateHeure] > DATEADD(HOUR, - 24,GETUTCDATE())) AND ([DateHeure] < GETUTCDATE()) AND [Matricule] <> '' ) 
AS T 
Viewing all 4164 articles
Browse latest View live


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