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

Determining the correct Connection string

$
0
0

I am new to ADO. I tried to copy/paste from what I found in another forum, but I got nowhere. Here is my set-up. I host the SQL Server database. I set it up for Active Directory authentication. Another company sends me excel spreadsheets by email. I want to basically insert the data from the Excel spreadsheet into my database. Here is the general idea:

When an email comes, I have an Outlook script grab the attachment. If it is an excel file, it opens it up. Once it is open, it figures out how many rows the spreadsheet has. Then, it goes row-by-row creating a SQL string to insert data into my database. Once it finishes, it opens a connection to my database and runs the SQL string I just created. Next, I determine what was deleted from the last update, and I delete my master data table. Then, I determine what was added from the last update, and I add it to the master data table. Finally, I remove the old data, copy the new data to the old data, and delete the new data. This will set it up for the next time that the spreadsheet arrives.

Here is my code:

'Initialize New Variables Dim iMaxRow, iRowsToUpdate As Integer Dim strInsert As String Dim dbSQL As ADODB.Connection 'Figure out how many rows there are With xlWorkbook.Worksheets(1) .Activate .Cells(1, 1).Select End With While Selection.Row < 65536 iMaxRow = Selection.Row - 1 Selection.End(xlDown).Select Wend 'Start building the INSERT statement strInsert = "INSERT INTO dbo.NewData (Field1, Field2, Field3, Field4)" & vbCrLf & "VALUES" & vbCrLf iRowsToUpdate = 0 If iMaxRow > 1 Then For iRow = 2 To iMaxRow With xlWorkbook.Worksheets(1) 'Figure out if you want to add the row If <true row is useful> Then iRowsToUpdate = iRowsToUpdate + 1 'After first row to add, need a comma If iRowsToUpdate > 1 Then strInsert = strInsert & "," & vbCrLf End If 'Reformat the data strInsert = strInsert & "(" & _ .Cells(iRow, 1).Value & "," & _ 'Call FormatValue2 function FormatValue2(.Cells(iRow, 3).Value) & "," & _ 'Call FormatValue3 function FormatValue3(.Cells(iRow, 4).Value) & "," & _ .Cells(iRow, 5).Value & ")" End If End With Next End If If iRowsToUpdate > 1 Then 'Add the semicolon to complete the SQL statement strInsert = strInsert & ";" 'Open up a connection Set dbSQL = New ADODB.Connection 'Set the ConnectionString dbSQL.ConnectionString = "driver={SQL Server};" & _"server=localhost;database=MyDatabase"

'Open the connection to the database dbSQL.Open dbSQL.Execute (strInsert) 'Figure out which rows were removed from the previous update and delete them from the MasterData table strSQL = "DELETE FROM dbo.MasterData" & vbCrLf & _"WHERE (Field1, Field2, Field3, Field4) IN " & vbCrLf & _"(SELECT Field1, Field2, Field3, Field4" & vbCrLf & _"FROM dbo.OldData" & vbCrLf & _"WHERE (Field1, Field2, Field3, Field4) NOT IN " & vbCrLf & _"(SELECT Field1, Field2, Field3, Field4" & vbCrLf & _"FROM dbo.NewData))" dbSQL.Execute (strSQL) 'Figure out which rows were not in the previous update and add them to the MasterData table strSQL = "INSERT INTO dbo.MasterData (Field1, Field2, Field3, Field4)" & vbCrLf & _"SELECT Field1, Field2, Field3, Field4" & vbCrLf & _"FROM dbo.NewData" & vbCrLf & _"WHERE (Field1, Field2, Field3, Field4) NOT IN " & vbCrLf & _"(SELECT Field1, Field2, Field3, Field4" & vbCrLf & _"FROM dbo.OldData)" dbSQL.Execute (strSQL) 'Clear all data from the OldData table strSQL = "DELETE * FROM dbo.OldData" dbSQL.Execute (strSQL) 'Move the data from the NewData table to the OldData table strSQL = "INSERT INTO dbo.OldData (Field1, Field2, Field3, Field4)" & vbCrLf & _"SELECT Field1, Field2, Field3, Field4" & vbCrLf & _"FROM dbo.NewData" dbSQL.Execute (strSQL) 'Clear the NewData table to get it ready for the next spreadsheet that arrives strSQL = "DELETE * FROM dbo.NewData" dbSQL.Execute (strSQL) dbSQL.CommitTrans dbSQL.Close Set dbSQL = Nothing End If

I have no clue how it works so far, as I cannot even get it to connect to the database. I do not understand the connection strings at all.

ADODB causing LabVIEW to recompile code

$
0
0

I hope this post is roughly in the right place.

I am using LabVIEW to interact with an SQL database and please forgive me for not using ANY of the correct terms...here goes.

I share a snippet of code between developers using GIT source code control.  I have a nuisance file that LabVIEW wants to recompile when shared between computers.  It seems to occur when a call is made to an ADODB.recordset object.  Both computers run Windows 7 64-bit and the LabVIEW2015.  ADODB seems to be 7.0.3300.0 in the windows/assembly folder for both computers.  ODBC 32-bit file dsn is what is used (to connect/authenticate?).  What other drivers/software could possibly be being used to access an SQL database.  Is .NET involved perhaps?  

The question basically is how to determine what driver/software is different between the computers.  I don't have a deep understanding of how all the pieces fit together between the operating system, drivers, databases and LabVIEW...I just know that I wobble my way through until it works.I'm not expecting anyone to answer from the LabVIEW side of things, but at least I'm hoping for guidance to know where to look.

SQL Server JDBC Driver fails to call a Stored Procedure in SQL Server

$
0
0

I have a SQL server (2014 server) that has a stored procedure that takes a parameter and returns a resultset.

When I call this stored procedure using the SQL JDBC 6.0 Driver, it fails:

com.microsoft.sqlserver.jdbc.SQLServerException: Parameter @pJobStatusID was not defined for stored procedure dbo.ImportQueueJobStateGetByJobStatusID.

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191)

at com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.findColumn(SQLServerCallableStatement.java:1275)

at com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.setInt(SQLServerCallableStatement.java:1683)

at com.zillow.db.CallableStatementImpl.setInt(CallableStatementImpl.java:338)

at com.zillow.dataimport.countydirect.queue.QueueManager$2.doInCallableStatement(QueueManager.java:124)


This is how I am calling it:

                tasks = (List<QueueEntry>) jdbcTemplate.execute("{ call dbo.ImportQueueJobStateGetByJobStatusID(?, ?, ?) }",
                        new CallableStatementCallback() {
                            public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {

                                List<QueueEntry> tasks = new ArrayList<QueueEntry>();

                                cs.setInt("@pJobStatusID", jobStatusId); // return all entries
                                cs.setInt("@pImportQueueIDStart", queueIdStart);
                                cs.setInt("@pBatchSize", batchSize);

                                ResultSet rs = cs.executeQuery();

This is the definition of the stored procedure:

ALTER PROCEDURE dbo.ImportQueueJobStateGetByJobStatusID (
    @pJobStatusID int,
    @pImportQueueIDStart int,
    @pBatchsize int
)
AS


I am calling it through Spring Framework JDBC template.

This same call works if I use the JTDS driver.

Any idea what I am doing wrong?


feroze
--
My blog (including System.Net topics

 Subscribe in a reader

Instruction on how to create a tracelog with your System.Net application
System.Net Links and HOWTOs

ODBC for Linux CentOS (SQLDriverConnectW)

$
0
0

I have just downloaded and installed ODBC 11 driver for Linux CentOS.
I have added the section defining the connection into odbc.ini and checked with isql.
Now I am trying to connect to SQL Server using it’s IPv4 address.
But SQLConnectW and SQLDriverConnectW fail both.
For SQLDriverConnectW I use the following Con Str:
DSN=<Section name as defined in odbc.ini>;UID=<username>:PWD=<password>;
With same params isql works just fine (isql -v <Section name as defined in odbc.ini> <username> <password>
What’s wrong?
What should I write to use SQLConnectW?
Thank you in advance,
   Ben

Connecting to SQLSERVER DB (on windows 2008 server) from Oracle 12C DB(on Linux 6.7)

$
0
0

Using DG4ODBC now. facing some errors with some select statements. Is there an alternate way to access SQLSVR data from Oracle

error: ORA - 28500

ODBC SQLSVR driver: the multipart identifier could not be bound. (42000,NativeErr=4104)  (42000, Native Err=8180)

What are the options for Connection pooling with MS JDBC Driver ?

How to import Contoso retail database into SQL Server 2016

$
0
0

I downloaded the ContosoBIdemoBAK.exe and ContoslBIdemoABF.exe files and decompressed them to a directory on my hard disk. After opening SQL Server Management Studio and selecting Database Engine, I entered the server name. However Management Studio told me no backup set selected for restoration. I copied all the decompressed files into the directory where Management Studio was apparently expecting the  decompressed files to be, but they did not show up in the Restore Database window.

How can I import the Contoso database into SQL Server?


Allen G. Taylor

Login Failed. The login is from an untrusted domain

$
0
0

Error:

________

Microsoft SQL Server Native Client Version 10.50.1600

Running connectivity tests...

Attempting connection
[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

TESTS FAILED!

______

-I have a Domain user name

--PC1 member of domain

--PC2 not a member of domain

I dont have access to SQL Server 2008.

I receive the above error on PC2.  Is there a workaround for PC2?


SQL Server 2012 Compatability

$
0
0

Hi Team,

We are currently upgrading database of an application (classic ASP based) from version SQL Server 2008 to 2012. This application executes numerous of embedded SQL scripts through AdoRecordset. At the time, there is no plan to redesign the data access layer with ADO.NET/ORM.

With the given situation,  

we would need to confirm that whether any code/driver changes required to make it compatible with SQL server 2012?

Or It would work as expected without any changes?

Were any announcement from Microsoft on support perspective and so?

What should be the ideal approach when continue connecting from classic asp/any legacy technology based application to latest SQL server version?

Please share your recommendation that would helpful us to make a decision.

Thanks.

SPNs in isolated network/SQL Server access remotely

$
0
0

I was wondering if we open up SQL Server port in isolated network and try to connect to it remotely using IPAddress and Port from core domain.

The only way to do that will be using SQL Authentication right?

Or is it possible to do it via Windows authentication? This would require SPNs if using integrated authentication and since this is in isolated network/different domain, will it be available?

Connection Timeout and ODBC Native Client

$
0
0

I use ODBC SQL Native Client to connect to SQL Server.

When I call SQLDriverConnect to connect to an SQL Server instance and  server is down, the function takes 20+ seconds to return. I want to be able to detect it sooner, lets say after 3 secs, but there is no connection timeout property like there is in .NET SqlClient or OLEDB using Native Client.

I tried using SQL_ATTR_LOGIN_TIMEOUT but it is not implemented in SQL Native Client. I also tried to enable asynchronous mode for connecting using SQLSetConnectAttrand SQL_ATTR_ASYNC_ENABLE but still the delay is the same. The login doesn't seem to happen asynchronously.

Is there any way using ODBC and Native Client to detect that the server is down, or get a login timeout sooner? Maybe some configuration in the registry or the server? My application cannot wait for so long when there is a problem. I am using also ODBC Connection pooling and I use SQLDriverConnect very often.

Thank you,

Dimitris

How does ApplicationIntent=ReadOnly work with connection pooling?

$
0
0

How does ApplicationIntent=ReadOnly work with connection pooling?

If a connection is created as readonly and is part of a pool, it does not get closed when the application closes the connection. It gets returned to the pool. So, if subsequently another thread requests a connection from the pool and gets a readonly connection, wont it cause a problem if the client wants to do a Update operation?

In other words, is ReadOnly application intent incompatible with connection pooling? Or, am I missing something>


feroze
--
My blog (including System.Net topics

 Subscribe in a reader

Instruction on how to create a tracelog with your System.Net application
System.Net Links and HOWTOs

The server failed to resume transaction error with SQL Server 2014 Database

$
0
0

hi!

I am getting an exception

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: com.microsoft.sqlserver.jdbc.SQLServerException: The server failed to resume the transaction. Desc:1ec00000002.
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:191)
	at com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.findColumn(SQLServerCallableStatement.java:1264)
	at com.microsoft.sqlserver.jdbc.SQLServerCallableStatement.setInt(SQLServerCallableStatement.java:2018)

when calling a stored procedure. My java code looks like this:

        jdbcTemplate.execute("{ call dbo.updateEntry(?, ?, ?, ?) }",
                new CallableStatementCallback()
                {
                    public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException
                    {

                        cs.setInt("pQueueid", zpConversionQueueID);
                        cs.setInt("pPid", processControlId);
                        cs.setInt("pJobStatusID", jobStatus.getCode());
                        cs.setString("pLastUpdateBy", lastUpdateBy);

                        cs.execute();

                        return null;
                    }
                });

The stored procedure is not doing any transaction management.

I am using our custom connection pooling mechanism. ALl this worked fine with the JTDS driver, but failing when I swap in the SQL server driver.

Any ideas what I am doing wrong?


feroze
--
My blog (including System.Net topics

 Subscribe in a reader

Instruction on how to create a tracelog with your System.Net application
System.Net Links and HOWTOs

Query is running slowly in SQL server 2014

$
0
0

Following query is running if the database compatibility level is 120 (2014). It is running fine for lower level.

         

declare @dist Int,@rango int, @FI DATETIME,@FF DATETIME 

SET @FI = cast(convert(nvarchar,'2015-01-15 09:17:00.000') as datetime)
SET @FF = cast(convert(nvarchar,'2015-01-15 09:19:00.000') as datetime)

SELECT  * 
FROM [My_Database].[dbo].[My_table] with (nolock)
WHERE FechaEmision BETWEEN @FI and @FF and
 CodigoRuta = '00001' and 

Localidad = '01'

Structure of the table is:

Column_nameTypeComputedLengthPrecScaleNullableTrimTrailingBlanksFixedLenNullInSourceCollation
CodigoRutavarcharno6        yesno yesLatin1_General_CI_AS
FechaEmisiondatetimeno8        yes(n/a)(n/a) NULL
FechaSatellitedatetimeno8        yes (n/a)(n/a)NULL
Latituddecimalno9 18   8    yes(n/a)(n/a)NULL
Longituddecimalno9 18   8    yes(n/a)(n/a)NULL
Correlativointno4 10   0    yes(n/a)(n/a)NULL
Lotechar no10       yesno yesLatin1_General_CI_AS
Localidadvarcharno15        yesno yesLatin1_General_CI_AS


Index:

index_nameindex_descriptionindex_keys
IX_CapturaGalileononclustered located on PRIMARYCodigoRuta, FechaEmision, Latitud, Longitud

Single Line view from many columns data V:SQL 2016

$
0
0

My table look like this ,

CREATE TABLE dbo.test ( action_id int, person_num nvarchar(40), creation_date nvarchar(20), event_name nvarchar(40), full_name nvarchar(40) );

 

INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('168448','10148','16477','7/21/2016 12:00','CLOCK_IN','1','DAY','OSU'); INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('168780','10148','16477','7/21/2016 15:00','CLOCK_OUT','1','DAY','OSU'); INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('169121','10148','16477','7/23/2016 7:00','CLOCK_IN','1','DAY','OSU'); INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('169146','10148','16477','7/23/2016 9:00','CLOCK_OUT','1','DAY','OSU'); INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('169148','10148','16477','7/23/2016 13:00','CLOCK_IN','1','DAY','OSU'); INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('169340','10148','16477','7/23/2016 17:00','CLOCK_OUT','1','DAY','OSU');

INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('169340','10148','16477','7/23/2016 17:30','CLOCK_IN','1','DAY','OSU');

INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('169340','10148','16477','7/23/2016 18:00','CLOCK_OUT','1','DAY','OSU');  INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('169650','10146','16477','7/24/2016 18:10','CLOCK_IN','1','DAY','keni'); INSERT INTO dbo.test (`action_id`,`person_num`,creation_date`,`event_name`,`full_name`) VALUES ('175112','10146','16477','7/24/2016 18:20','CLOCK_OUT','1','DAY','keni');





























SQL QUERY BELOW, this gives only clockin1,clockout1,clockin2,clockout2, instead table as is,

     WITH    Prep
               AS ( SELECT   CAST(dbo.UtcToLocal(creation_date) AS DATE) AS creation_date ,
                             person_num ,
                             full_name ,
                             MIN(CASE event_name
                                   WHEN 'CLOCK_IN'
                                   THEN CAST(dbo.UtcToLocal(creation_date) AS TIME)
                                 END) AS CLOCK_IN1 ,
                             MIN(CASE event_name
                                   WHEN 'CLOCK_OUT'
                                   THEN CAST(dbo.UtcToLocal(creation_date) AS TIME)
                                 END) AS CLOCK_OUT1 ,
                             NULLIF(MAX(CASE event_name
                                          WHEN 'CLOCK_IN'
                                          THEN CAST(dbo.UtcToLocal(creation_date) AS TIME)
                                        END),
                                    MIN(CASE event_name
                                          WHEN 'CLOCK_IN'
                                          THEN CAST(dbo.UtcToLocal(creation_date) AS TIME)
                                        END)) AS CLOCK_IN2 ,
                             NULLIF(MAX(CASE event_name
                                          WHEN 'CLOCK_OUT'
                                          THEN CAST(dbo.UtcToLocal(creation_date) AS TIME)
                                        END),
                                    MIN(CASE event_name
                                          WHEN 'CLOCK_OUT'
                                          THEN CAST(dbo.UtcToLocal(creation_date) AS TIME)
                                        END)) AS CLOCK_OUT2
                    FROM     TEST
                    GROUP BY ALL CAST(dbo.UtcToLocal(creation_date) AS DATE) ,
                             person_num ,
                             full_name
                  )
         SELECT  creation_Date ,
                 person_num ,
                 full_name ,
                 CLOCK_IN1 ,
                 CLOCK_OUT1 ,
                 CLOCK_IN2 ,
                 CLOCK_OUT2 ,
                 DATEDIFF(MINUTE, CLOCK_IN1, CLOCK_OUT1) / 60+ ISNULL(DATEDIFF(MINUTE, CLOCK_IN2, CLOCK_OUT2) / 60, 0) AS HoursWorked
         FROM    Prep

Desired output(SQL version 2016)

Creation_date

Name

Clockin1

Clock out1

Clockin2

Clockout2

Clockin3

Clockout3

Total hours

 

21/07/2016

osu

12:00

15:00

 

 

 

 

3

 

23/07/2016

osu

7:00

9:00

13:00

17:00

17:30

18:00

6.30

 

 

 

 

 

 

 

 

 

 

 


























Binding Error

$
0
0

When i tried to bind the table to the Visual studio Form by dropping it on the form am receiving the below error. Can anyone please help me?


"" An error occurred while performing the drop:

Code generation for property 'UpdateOrder' failed. Error was: 'Type 'Newlogin.Test1DataSetTableAdapters. TableAdapterManager+UpdateOrderOption' is not available in the target framework'. ""




what type of data found in mdf and ldf and ndf files

$
0
0

when create database in SQL server 2008 it contain three files

mdf

ldf

ndf

what i need to ask what type of data saved in mdf and ldf and ndf

to be more clear see example following

if i have HR DATABASE 

and inside HR database i have table employee

table employee have FOUR fields

ID

NAME

ADDRESS

PHONE

data inside table as following

ID    NAME        ADDRESS       PHONE

1      MARTEN     CAIRO         01222222

2      WILSON     USA            0765444

3      MICHEL     FRANCE       0997766

my question

IN which files(mdf,ldf,ndf) 

saved record of data

in which  files(mdf,ldf,ndf)  saved fileds and table object without data

table employee have FOUR fields

ID

NAME

ADDRESS

PHONE


Lost connectivity from virtual machine to sql servers

$
0
0

I'm kind of at a loss with troubleshooting the issue below. I'd appreciate any tips re what to try next.

I work on a windows 7 pro workstation using odbc to connect to various sql server instances. On the workstation I can get to all instances: it's own sql server 2008 instance and a sql server 2012 instance on a server, for example. The workstation also runs some virtualbox vms which normally connect to the same sql server instances. I migrated the workstation to a new box and after the migration can't connect to either of the sql servers via odbc? Other vms still connect.

I have tested creating new odbc connections from other vms and they work normally. I can easily connect using 32 bit odbc dialog to both default instances on server and workstation. If I try to create a new odbc connection via the same dialog on the problematic vm, it times out at the point where it would normally show the page that lists the db on the selected sql server. I have the same result if I enter the workstation's ip address...it times out.

All of these use windows authentication. It's a windows 2012 domain network.

I've restarted the vm and the host (the workstation). I am not sure what the next troubleshooting step might be?

ODBC dsn not showing new tables

$
0
0

Server: SQL Server 2012 SP3 / Windows Server 2012

Client: Windows 7 Pro 64 bit, SQLCLN 11

I have a user trying to retrieve tables from a SQL 2012 default instance. User has db_datareader permissions on the database. After setting up the ODBC connection, if I add a new table (WAREHOUSE.NewTable1), it does not show in the list of available tables in the ODBC connection. The user can select and view all tables in the database, including all tables in the WAREHOUSE schema, except this particular table.

What I've tried so far:

1. Have the user connect via SSMS - Success, user can view the table

2. Have the user recreate the ODBC connection - Fail, user cannot view table

3. Add new table other than WAREHOUSE.NewTable1 - Success, user can select from added table, in any schema

4. Explicitly add the schema permissions to the user - Fail, user cannot view table

I am convinced that it is not on the SQL Server side (security / permissions). I believe it to be in the ODBC connection, but don't know where, since it is pretty much a black box without a ton of configuration. I have seen a problem with 32 bit ODBC vs 64 bit ODBC but that was connecting to a legacy AS400 data source and I'm pretty sure that isn't a problem here. Any ideas?

MS OLE DB Provider for DB2 V5

$
0
0

Hello,

Just purchased SQL Server 2014.  I am trying to get a linked server setup to our AS400 using the MS OLE DB Provider for DB2 v5 x64.

I've got the linked server setup, connected and working but it is not translating the CCSID 65535 fields.  I have set the option "Process binary as character=true" and "Binary Codepage=37".  From what I have read, these to options should solve my problem but they are not doing the trick.  The issue is anything that is set with a CCSID 65535 on the 400 is being returned something like this "0x40404040404040404040".  Fields with a CCSID of 37 are being returned normal and readable.  

I should mention, this same setup is working on our SQL 2005 server as we speak.  It is an older version of the OLE DB Provider for DB2 and does not contain the "Binary Codepage=37" but I have tried it with that, without that and with Binary Codepage=0 on the new server to no avail.  I have also tried version 4 of the Provider, Translate binary as character=true, BinasChar=true, and none of it works.

Anyone have any suggestions?  I worked on this for a full day and couldn't get it to go.

Viewing all 4164 articles
Browse latest View live


Latest Images

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