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

OLEDB Bookmarks

$
0
0

I generated an ATL OLEDB Consumer with the VS 2005 wizard.  The table is very simple and is located on my local SQL Server.  It has two varchar columns and no keys or constraints.  I can modify, insert and delete rows with no problem.

 

Now I want to use bookmarks.  I added the following to the accessor class:

 

1. CBookmark<4> m_bookmark; // member variable

2. pPropSet->AddProperty(DBPROP_IRowsetLocate, true); // rowset property

3. BOOKMARK_ENTRY(m_bookmark) // column map entry

 

Now I can delete but I can no longer modify or insert.  The error is DB_E_ERRORSOCCURED and the status of the two columns after a setdata or insert is DBSTATUS_E_UNAVAILABLE.  This is the only error information available.

 

When I comment out the bookmark entry from the column map, I can modify, insert and delete again.  The problem appears to be in how IRowsetChange handles bookmarks.  I tried adding bookmarks to other tables using the above 3 steps and they also refuse to modify or insert with bookmarks enabled.

 

The bookmarks appear to be correct, as I can do a successful MoveToBookmark for any row in the table.

 

My environment:  Windows XP SP2, VC++ 2005, SQL Server 2005 Express, WTL 8.0

 

Any ideas?


Intermittent ODBC connect failure to local machine using Trusted Authentication

$
0
0

We have a service which uses ODBC to connect to a local database using Trusted Authentication. The connection string (for SQL2008) is:

DRIVER=SQL Server Native Client 10.0;SERVER=.\ MyInstance;UID=;Trusted_Connection=Yes;APP=MyInstance;WSID=.\ MyInstance;DATABASE=%s;

Where %s is replaced with the database name. This is working on hundreds of sites. On two sites it works most of the time, but occasionally fails with:

Login failed for user 'NT AUTHORITY\SYSTEM'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]

Which is displayed in the event log just before our event log entry of failure to open the database.

The same service shows opening of other databases without a problem, it also shows the opening of the failed database later in time. It can be any of the databases we have. To be clear we have a multi-threaded server that allows a user to select which entity to work on and then opens that entities database. They can switch entities and multiple users can access the same entity.

We have this working on all MS-SQL database versions from 2005 to 2016. (with appropriate connection strings)

There are no other entries in the Event log near when this happens to point to some other failure. Note changing to SQL authentication is not an option as we would need to update hundreds of sites, modify our install software etc.

I seem to have gone bald and there seems to be a soft pile near my feet. Please Help…

Login failed for user 'NT AUTHORITY\SYSTEM' In application spawned from service

$
0
0

We have a service that connects to a local database using (SQL2008R2):

DRIVER=SQL ServerNativeClient10.0;SERVER=.\ MyInstance;UID=;Trusted_Connection=Yes;APP=MyInstance;WSID=.\ MyInstance;DATABASE=%s;

This service can download an update and then execute the update with a simple CreateProcess() call using NULL for the security attributes. The update stops the service (Waiting for confirmation of it being stopped), attaches the main database to read a few local settings, disconnects the database and extracts the new files and does its update and then restarts the service. This is working on hundreds of sites running SQL 2005-2016, but on a few we are getting:

Login failed for user 'NT AUTHORITY\SYSTEM'. Reason: Failed to open the explicitly specified database. [CLIENT: <local machine>]

when trying to attach to the database from the update program. To be clear, the exact same database was successfully attached in the Service process using exactly the same connection string and ODBC attach code.

When the update program is run from the Desktop (Run As Administrator) it works perfectly. The main problem is that updates happen at 3am and when the customer comes in the next morning (usually before the start of our business day) the system needs our manual intervention to get it running again.

I can't change the connection authentication method as it would require updating hundreds of sites. I am worried that there is something I am missing and sometime in the future all the sites will have this issue.

Any ideas are welcome, but this is not a simple problem as it is consistent on one system, inconsistent of a few more and works perfectly on hundreds of other systems.

Thanks.

Cannot insert more than 16 columns of data into table

$
0
0

Hi,

I am using the SQLServerBulkCopy class to copy data from a csv file into table. However I cannot insert into a table with more than 16 columns. When the number of columns is less than 17, say 16, it is working perfectly. Is anyone having the similar issue? I am using JAVA and Microsoft SQL Server 2008 R2 Management Studio 10. The csv file only have two lines, the 1st line is the header and the 2nd line is the data. All the 17 columns are VARCHAR(10) and they have the same value "1".

import java.sql.*;

import com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord;
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy;

public class Program
{
    public static void main(String[] args)
    {
        String connectionString = GetConnectionString();
        SQLServerBulkCSVFileRecord fileRecord = null;
        try
        {            
            // Get data from the source file by loading it into a class that implements ISQLServerBulkRecord.
            // Here we are using the SQLServerBulkCSVFileRecord implementation to import the example CSV file.
            fileRecord = new SQLServerBulkCSVFileRecord("F:/test/test1.csv", true);    

            // Set the metadata for each column to be copied.
            for(int i = 0;i < 17;i++)
            {
            	fileRecord.addColumnMetadata(i+1, null, java.sql.Types.VARCHAR, 10, 0);
            }
            // Open a destinationConnectio to the AdventureWorks database. 
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            try (Connection destinationConnection = DriverManager.getConnection(connectionString))
            {
                try (Statement stmt = destinationConnection.createStatement())
                {
                    // Perform an initial count on the destination table.
                    long countStart = 0;
                    try (ResultSet rsRowCount = stmt.executeQuery("SELECT COUNT(*) FROM dbo.BulkCopyDemoDifferentColumns1;"))
                    {
                        rsRowCount.next();
                        countStart = rsRowCount.getInt(1);
                        System.out.println("Starting row count = " + countStart);
                    }

                    // Set up the bulk copy object.  
                    // Note that the column positions in the source 
                    // data reader match the column positions in  
                    // the destination table so there is no need to 
                    // map columns. 
                    try (SQLServerBulkCopy bulkCopy =
                               new SQLServerBulkCopy(destinationConnection))
                    {
                        bulkCopy.setDestinationTableName("dbo.BulkCopyDemoDifferentColumns1");

                        try
                        {
                            // Write from the source to the destination.
                            bulkCopy.writeToServer(fileRecord);
                        }
                        catch (Exception e)
                        {
                            // Handle any errors that may have occurred.
                            e.printStackTrace();
                        }
                    }

                    // Perform a final count on the destination  
                    // table to see how many rows were added.
                    try (ResultSet rsRowCount = stmt.executeQuery(
                            "SELECT COUNT(*) FROM dbo.BulkCopyDemoDifferentColumns1;"))
                    {
                        rsRowCount.next();
                        long countEnd = rsRowCount.getInt(1);
                        System.out.println("Ending row count = " + countEnd);
                        System.out.println((countEnd - countStart) + " rows were added.");
                    }
                }
            }
        }
        catch (Exception e)
        {
            // Handle any errors that may have occurred.
            e.printStackTrace();
        }
        finally
        {
            if (fileRecord != null) try { fileRecord.close(); } catch(Exception e) {}
        }
    }

    // To avoid storing the sourceConnection String in your code,  
    // you can retrieve it from a configuration file. 
    private static String GetConnectionString()
    {

        
    }
}


Here is the exception msg:

com.microsoft.sqlserver.jdbc.SQLServerException: Column 17 is invalid.  Please check your column mappings.
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.validateColumnMappings(SQLServerBulkCopy.java:1690)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:1510)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:616)

And this is the table schema:

create table BulkCopyDemoDifferentColumns1
(
name1 VARCHAR(10),
name2 VARCHAR(10),
name3 VARCHAR(10),
name4 VARCHAR(10),
name5 VARCHAR(10),
name6 VARCHAR(10),
name7 VARCHAR(10),
name8 VARCHAR(10),
name9 VARCHAR(10),
name10 VARCHAR(10),
name11 VARCHAR(10),
name12 VARCHAR(10),
name13 VARCHAR(10),
name14 VARCHAR(10),
name15 VARCHAR(10),
name16 VARCHAR(10),
name17 VARCHAR(10)
)

Database creation fails

$
0
0

I have a Developer edition 2016 or 2017 of MSMS, cannot figure out. When I installed it, I had to attach a few existing databases, perhaps a dozen. They had been created years ago and worked quite well. So, this is what happened. I could attach about 3 or 4 databases, fortunately the most important ones, but now I want to continue and the system refuses to attach others. I have this database "imaging.mdf" and the corresponding log file: "imaging_log.ldf" I had to go to the folder and give all permissions to both files. Permissions for .mdf file seem to have stuck there, but the log file is rejected. It says I don't have permission to attach it. When I go to that file and click properties, a ridiculous situation is observed. guest has full rights and the administrator only read. All useful checkboxes are dimmed, they are useless.

I've been thinking about reading this file's header, 502 bytes or so and perhaps correct in in the raw memory. I've done such things before (reading RAM memory byte by byte) but when I read mapping for the header I could not find anything related.

Microsoft makes my life as hard as possible. It is simply horrible.

Any ideas?

Thanks, - Alex

IIS unable to connect to SQL Server when TLS 1.0 is disabled

$
0
0

Hi all, I keep finding posts about this and keep trying to solutions and they fail for me so I hope someone can help.

We have Windows Server 2012 running IIS and SQL Server 2012. ODBC driver is 2014.120.5543.11 (date 2/28/2017). Everything is fine until TLS 1.0 is disabled (via registry using IISCrypto/reboot). Unable to connect to SQL Server and we get .NET errors. .NET framework is 4.6.01590. SQL Server is 11.0.6598.0 (SQL Server 2012 SP3, CU 9)

I'm open to ideas, thank you!




Update command

$
0
0

Is is possible to do something like...

update ub_meter set me_status  = 'D' where recordnumber > 1000 and recordnumber < 2000

Thanks in advance.


DrewT1755

Can I have a few instances with SQL Server developer edition 2017?

$
0
0

I do have one instance that is working OK. I would like to generate perhaps 3-4 other instances, named instances. Can I do it with Developer edition?

Thanks, - Alex


how to get data from file

$
0
0

hello,
i need to put data from sql server to file and get it to my program from this file ,
i need to make my program offline without needed to connect to sql server

How to do sum of field inner joined but no records

$
0
0

Hello There,

Here is my Query:

first table:   item                  second table:   purchase                third table:sale

id      itemname                   id      itemid       qty                       id      itemid     qty

1       samsung                       1      1              100                       1        1            80

2       motorola                       2      2              500

3       nokia

here is my sql code

temprs.Open "SELECT i.itemname, sum(p.qty), sum(s.qty) FROM (item as i INNER JOIN sale as s ON i.id = s.itemid) INNER JOIN purchase as p ON i.id = p.itemid group by i.itemname"

Result shows Samsung only and finds no records about motorola and nokia

What would be the code please help.....?   Thanks in advance

[unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.1.so.0.1

$
0
0

Hi,

I am trying to run windows command line program that uses ODBC to connect to a remote MSSQL server. It works fine in Windows 10. Now I want to run the same program in Linux using Wine. I have installed unixODBC. ODBC connection is working fine. I can connect to the remote MSSQL server using isql command.

But when I run my windows program using wine. I get this error log. What should I do?

[unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.1.so.0.1

cat /etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.1.so.0.1
UsageCount=1
Trace = Yes
TraceFile = /var/log/odbc.log

This file does exist.

ldd /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.1.so
o.0.1rselinux-vdso.so.1 (0x00007ffffbf8a000)sodbcsql17/lib64/libmsodbcsql-17.1.so
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8695587000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f869537f000)
    libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007f869516a000)
    libcrypto.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2 (0x00007f8694d06000)
    libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f8694a2c000)
    libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f86947e1000)
    libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f8694561000)
    libssl.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2 (0x00007f86942f8000)
    libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f86940f3000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f8693d71000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8693a6d000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8693856000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8693639000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f869329a000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f8695b99000)
    libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f8693090000)
    libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f8692e5d000)
    libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f8692c59000)
    libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f8692a4d000)
    libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f8692849000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f8692632000)
    libnghttp2.so.14 => /usr/lib/x86_64-linux-gnu/libnghttp2.so.14 (0x00007f869240c000)
    libidn2.so.0 => /usr/lib/x86_64-linux-gnu/libidn2.so.0 (0x00007f86921ea000)
    librtmp.so.1 => /usr/lib/x86_64-linux-gnu/librtmp.so.1 (0x00007f8691fcd000)
    libssh2.so.1 => /usr/lib/x86_64-linux-gnu/libssh2.so.1 (0x00007f8691da1000)
    libpsl.so.5 => /usr/lib/x86_64-linux-gnu/libpsl.so.5 (0x00007f8691b93000)
    liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f8691984000)
    libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007f8691733000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f8691519000)
    libunistring.so.0 => /usr/lib/x86_64-linux-gnu/libunistring.so.0 (0x00007f8691202000)
    libgnutls.so.30 => /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007f8690e69000)
    libhogweed.so.4 => /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007f8690c34000)
    libnettle.so.6 => /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007f86909fd000)
    libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f869077a000)
    libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f869046a000)
    libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007f869024f000)
    libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f868ffea000)
    libidn.so.11 => /lib/x86_64-linux-gnu/libidn.so.11 (0x00007f868fdb6000)
    libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f868fba3000)
    libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f868f98f000)
    libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f868f786000)


Obfuscation in SQL Server 2016 - Application at record level

$
0
0

Hi all

I've read a couple of articles about obfuscation in SQL Server 2016 but neither really detail if obfuscation rules can be applied to columns on specific records (not all within a table). I suspect this isn't supported, but just wondered if someone could confirm?

If this is the case, does anyone know if there are plans to support this in future builds / releases?

Thanks

Michael

Windows Server 2016, The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine

$
0
0

All,

We move our apps to Windows Server 2016 (from 2008 R2) and SQL Server 2016 (from 2014).

I tried import an Excel file into SQL server but it gave to The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

I installed both Microsoft AccessDatabaseEngine 2010 and 2016. But it does not work.

Actually, it is not the SQL server issue. I can import the Excel file from my desktop to the same SQL DB. But I don't know where else to post.

Thanks,

John

SQLColAttribute issue

$
0
0

Hi,

I'm using SQL Server 2005 at the moment with MSVC 2010.

This page: https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlcolattribute-function?view=sql-server-2017#example states:


[quote]

(DM) An asynchronously executing function was called for the connection handle that is associated with theStatementHandle. This aynchronous function was still executing when SQLColAttribute was called.

(DM) SQLExecute, SQLExecDirect, or SQLMoreResults was called for theStatementHandle and returned SQL_PARAM_DATA_AVAILABLE. This function was called before data was retrieved for all streamed parameters.

(DM) The function was called prior to calling SQLPrepare, SQLExecDirect, or a catalog function for the StatementHandle.

(DM) An asynchronously executing function (not this one) was called for the StatementHandle and was still executing when this function was called.

(DM) SQLExecute, SQLExecDirect, SQLBulkOperations, orSQLSetPos was called for the StatementHandle and returned SQL_NEED_DATA. This function was called before data was sent for all data-at-execution parameters or columns.

[/quote]

for the "Function sequence error".

However, the following code still produces this error:

[code]

ret = SQLColumn( stmt_col );

i = 0;

for( ret = SQLFetch( stmt_col ); ( ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO ) && ret != SQL_NO_DATA; ret = SQLFetch( stmt_col ) )

{

    ret = SQLColAttribute( stmt_colattr, (SQLUSMALLINT) i + 1, SQL_DESC_AUTO_UNIQUE_VALUE, NULL, 0, NULL, &autoincrement );
    i++;

}

[/code]

Am I missing something here? Or this error applies even on not SQLColAttribute() statement?

Thank you.

Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL)

$
0
0

Hi, 

We have existing application and using OLE DB provider for SQL native client 

since MultisubnetFailover was not supported earlier with OLE DB , we have decided to migrate to ODBC and since the release of MDOLEDBSQL Driver in March2018 , OLDEDB is undeprecated  and continue to support and meets our requirement as this has facility to support "MultiSubnetFailover" implemented with new release , we are updating the OLE DB driver 2018

have few queries to clarify to proceed

1. can we migrate from SQLNCLI to MSOLEDBSQL , replace sqlncli.h to msoledbsql.h?

2. In connection string adding the attribute "MultiSubnetFailover=true" does this helps in achieving Disaster recovery and High availability ? what additional changes are required ?

3. Does this also supports Azure Database ? what changes are required 

4. Is there any sample application to follow ? 

appreciate your help.

Thanks, 

Arathi


Time Change

$
0
0

Hi,

I am an engineer in Industrial automation sector.I am not an expert in SQL Database.I would like to ask my doubt;

* We have shipped running machine in Germany to India, In machine IPC using Microsoft SQL management studio 2008 R2 for
   logging production data. The SQL data base stored all data with time, while machine run in Germany.

   After reaching at India we have changed the machine regional time to Indian time zone. So is there any possible to change   
   all      stored time data to Indian time zone., ie, the logged German time data will change to Indian time in SQL Database ?

   Now in machine all time data is changing to Indian time. What will be the reason.?? We need it data as it is, means if it is       
   running in Germany data logged should be in German time zone. And if i changed time zone, there wont be any change in
   previous time data. Is it possible?

Thanks,

SQL 2016 - 13.0.5026.0 Linked server fails for domain\login sysadmin

$
0
0

Hi all.

Anybody else experience this?

It was working until I updated from RTM (13.0.1601.5)  to SP2. (13.0.5026.0)

Login failed for user 'DOMAIN\svc_SQL_AGNT_XXXX'. [SQLSTATE 28000] (Error 18456)

Yes the global service account
Previous message was ..... (Message 0)  ------------- Process End ------------------- [SQLSTATE 01000]

This is used in an agent job that was working ok.

P.S. The SP2 has been running fine in Development environment for a month now running the same jobs and connections.

ODBC drivers missing for Access,excel,oracle etc when trying to create any new system/user DSN through ODBC data source administrator

$
0
0
When i am trying to create any new System/User DSN drivers corresponding to all the databases except SQL server is not showing up in the wizard in ODBC data source administrator. I am using windows 7 , 64 bit machine

Finding more details on a failed login

$
0
0

Hello

I have a SQL server that is generating a lot of failed login attmepts in the logs

Login failed for user 'MY_DOMAIN\sqluser'. Reason: Failed to open the explicitly specified database. [CLIENT: 192.168.***.***]

 Error: 18456, Severity: 14, State: 38.

I assume it is trying to access a default database that is unavailable or no longer exists

Tracing back the IP I find it is our SSRS server.

So one of the many reports on there must be the issue.

I don't expect someone to manually open every report and check the data source so I was wondering it there is a way to narrow it down further?

Unfortunately the logs or the trace don't tell me what database it is trying to access?

thanks

Confusing SQL query, how could I write it shorter?

$
0
0

Is it possible to rewrite this query again in such a way that I could get the same result but

with a shorter query?

SELECT COUNT(UserName) As intCountResult FROM RegistrationList WHERE IDAutoNumber = @IDAutoNumber

AND TFirstVotes <> 0 AND TFirstVotes = (SELECT MAX(TFirstVotes) FROM RegistrationList)

AND TSecondVotes = (SELECT MAX(TSecondVotes) FROM RegistrationList WHERE

TFirstVotes = (SELECT MAX(TFirstVotes) FROM RegistrationList ))

AND TThirdVotes = (SELECT MAX(TThirdVotes) FROM RegistrationList

WHERE TFirstVotes = (SELECT MAX(TFirstVotes) FROM RegistrationList )

AND TSecondVotes = (SELECT MAX(TSecondVotes) FROM RegistrationList

WHERE TFirstVotes = (SELECT MAX(TFirstVotes) FROM RegistrationList ) ) )

Thanks to all


Viewing all 4164 articles
Browse latest View live


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