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

The OLE DB provider ....reported an error. Access denied.

$
0
0
I'm trying to export excel data to a SQL Server database as:

SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=D:\DATA_SOURCE\Data2.xlsx', 'SELECT * FROM [Sheet1$');

I get errors:

Error Message: The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. Access denied.


Is there any reason for this error message? Thanks.


Error 0x80004005 when open recordset via ADO

$
0
0

Hi,

I am using Visual C++ 2008 + ADO to connect to a SQL Server instance on local computer. After connecting to SQL Server, my program will do lengthy tasks which normally takes several hours. During this period, my program may open recordset from a SQL Server query to a SQL Server database. Sometimes, open recordset will fail and the error code is 0x80004005 without detailed coding meaning.

The characteristics of the error:

1. Only occurs in lengthy tasks which takes several hours to 10+ hours.

2. The frequency of the error occurance is 10% or less. Sometimes I need to run several days to reshow the error once.

Some Details:

1. I am using SQL Server 2008 R2.

My Analysis:

After searching on Google, it seems the error is "SQL Server connection error". But my SQL Server instance is installed on local computer where the program is running. So I guess maybe a lengthy operation on SQL Server will cause time out or auto-disconnect of the program?

Upgrading from SQLNCLI11 to MSOLEDBSQL

$
0
0
We are in the process of upgrading our sql server database to sql server 2017, after we upgraded some of our SSIS packages stopped working where we encountered the following issue: 
SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "The metadata could not be determined because statement 'REVERT --Check if SSB is enabled in this database' in procedure 'sp_send_dbmail' does not support metadata discovery."
After some research it looks like we need to change our provider from SQLNCLI11 to MSOLEDBSQL. My question is if we upgrade to MSOLEDBSQL is this backward compatible with anything that needs SQLNCLI11? And if we decide to stick with SQLNCLI11 is there any resolution/workaround for this error?

nvarchar(max) not working with ADO and ODBC Drivers other than "SQL Server"

$
0
0

I can read nvarchar(max) columns with ADO without any problems when I use "SQL Server" ODBC Driver.

I installed the newest ODBC Driver 17 for SQL Server v17.4.1.1 on my computer and tested it.

Now I don't get a result. When debugging, I can see that I get a result with the double amount of characters, but with a lot of null bytes and so I get an empty string.

It also doesn't work when I set DataTypeCompatibility=80.

I've also tried "ODBC Driver 11 for SQL Server", "ODBC Driver 13 for SQL Server" and "SQL Server Native Client 11.0"

Here is my test script. Just connect to any SQL Server.

What's wrong with my test code and how can I fix it?

Just rename strCon2 to strCon to test different connection strings.

Option Explicit Dim rs 'As ADODB.Recordset Dim con 'As ADODB.Connection Dim strCon 'As String Dim strCon2 'As String Dim SQL 'As String Const adOpenStatic = 3 Const adLockReadOnly = 1 Const adCmdText = 1 ' Open connection Set con = CreateObject("ADODB.Connection")

'Works strCon = "Driver={SQL Server}" & _";Server=server" & _";Database=master" & _";Uid=sa" & _";Pwd=" 'Doesn't work strCon2 = "Driver={ODBC Driver 17 for SQL Server}" & _";Server=server" & _";Database=master" & _";Uid=sa" & _";Pwd=" 'Doesn't work strCon2 = "Driver={ODBC Driver 17 for SQL Server}" & _";Server=server" & _";Database=master" & _";Uid=sa" & _";Pwd=" & _";DataTypeCompatibility=80" con.Open strCon Set rs = CreateObject("ADODB.Recordset") SQL = "select cast(N'abc123' as nvarchar(max)) as mycol" 'SQL = "select convert(nvarchar(max), N'abc123') as mycol" rs.Open SQL, con, adOpenStatic, adLockReadOnly, adCmdText msgbox rs.Fields(0).Value con.Close Set rs = Nothing Set con = Nothing


OSQL.exe

$
0
0

How to install only Osql.exe utility in Windows server 2012 R2 application server?

this utilized is need for some testing?

Need to count characters and group by that result

$
0
0

Noob here. I have a large table and I need to

  • count the number of characters in a single column U
  • where records have a corresponding value in another column Y
  • and group by the character count, so that I can see how many records in column U have 13 characters, 12, 11, etc.

So far I am at:

SELECT U, LEN(U) as Digits  
 FROM Table_OfExcitingStuff
WHERE [Y] IS NOT NULL

Group By.... Order By...?

I'm sorry if this has been asked elsewhere but I just can't find anything close to answering. Thanks.

Repeat Invoke Parameterized Query will Cause "Multiple-step OLE DB operation generated errors"

$
0
0

Hi,

I am using Visual C++ 2008 and ADO to access SQL Server. To improve the performance, I use parameterized Query, as below:

void CTestADOCmdDlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here
    _variant_t  vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR);
    _variant_t  vtEmpty2(DISP_E_PARAMNOTFOUND, VT_ERROR);

    ADODB::_ConnectionPtr  Conn1;
    ADODB::_CommandPtr     Cmd1;
    ADODB::_ParameterPtr   Param1;
    ADODB::_RecordsetPtr   Rs1;

    CoInitialize(NULL);

    // Trap any error/exception.
    try
    {
        // Create and Open Connection Object.
        Conn1.CreateInstance( __uuidof( ADODB::Connection) );
        Conn1->ConnectionString = _bstr_t(L"Provider=sqloledb;Data Source=MYPC;Integrated Security=SSPI;");
        Conn1->Open( _bstr_t(L""), _bstr_t(L""), _bstr_t(L""), -1 );
        
        Conn1->Execute(_bstr_t(_T("Create Database TestCmdDB")), NULL, ADODB::adCmdText | ADODB::adExecuteNoRecords);
        Conn1->Execute(_bstr_t(_T("Use TestCmdDB")), NULL, ADODB::adCmdText | ADODB::adExecuteNoRecords);
        
        Conn1->Execute(_bstr_t(_T("Create Table MyTable (MyID bigint);")), NULL, ADODB::adCmdText | ADODB::adExecuteNoRecords);

        // Create Command Object.
        Cmd1.CreateInstance( __uuidof( ADODB::Command ) );
        Cmd1->ActiveConnection = Conn1;
        Cmd1->CommandText = _bstr_t(L"SELECT * FROM MyTable WHERE MyID = ?");

        for (LONGLONG nIndex = 0; nIndex < 65536; nIndex ++)
        {
            // Create Parameter Object.
            Param1 = Cmd1->CreateParameter( _bstr_t(L""),
                ADODB::adBigInt,
                ADODB::adParamInput,
                -1,
                _variant_t( (LONGLONG) nIndex) );
            Param1->Value = _variant_t( (LONGLONG) nIndex );
            Cmd1->Parameters->Append( Param1 );

            // Open Recordset Object.
            Rs1 = Cmd1->Execute( &vtEmpty, &vtEmpty2, ADODB::adCmdText );
           
            // Do something with the recordset

            Rs1->Close();
        }

    }
    catch(_com_error& e)
    {
        CString strError = e.Description();
    }
    catch(...)             
    {  
    }   

    CoUninitialize();
}

In the for loop, the first time execution of:

Rs1 = Cmd1->Execute( &vtEmpty, &vtEmpty2, ADODB::adCmdText );

if OK. However, when in the second time exectution, it will raise an exception, the error description is:

"Multiple-step OLE DB operation generated errors"

I cannot understand the meaning. How to solve the problem?

Thanks

Could someone provide me some advice?

$
0
0

I am a new in SQL Sever and when i connect to SQL Server ,I get an error. Of course , I am not sure how I can solve it but try some ways by researching. Now, the way worked. However , I am not sure the reason why it shows error. 

Could some one show me the cause and provide me some solutions to help me avoid later error?


How do I select null

$
0
0

Hi everyone,
I use
select * from table
where column =null

to select null value . And then I get an error . Could you help me ?

Insert query not working with mssql driver

$
0
0

Hi,

I am trying to connect to mssql server 2014. I am using a proxy server in between to connect to the same. 

The 'SELECT' , 'UPDATE' , 'DELETE' query are working just fine. But the 'INSERT' query is going into processing state and never returns any thing. 

Could you please help me in this context.  I have already provided necessary data access permission to the user for the same. Is there any thing else I am missing here.

Thanks,

Vinit

Sap Labs India

Linked server creation failed with ODBC provider

$
0
0

Hi,

I am trying to create a linked server from one SQL Server to another with 'ODBC Driver 13 for SQL Server' by ODBC data source. But it is getting failed. Below is screen shot. Can anyone help to solve the issue?



Microsoft ODBC driver for SQL (version 13)

$
0
0

Have an old VB6 app using Microsoft ODBC driver for SQL v13 to connect to our sql server (v2016).

Using the default connect string from VB6, it appears to want to use named pipes.  How do I tell Microsoft ODBC driver for SQL to use TCP/IP to connect instead of named pipes?

I did try running cliconfg and enabled tcp/ip and disable named / pipes but that didn't help since server only has TCP enabled.

Data Moving from Column -1 to 0 "Randomly"

$
0
0

We are having an issue with our software where we have a client log in and change a name setting for data, which "randomly" switches the data from column -1 to column 0. This causes the data to disappear from their UI. I am saying it is doing this"randomly", but I know nothing is ever random. I have verified its not the  number of saves, some issue with how long it takes for them the save the change, among various other issues. I am also black box testing this so I don't have access to the code. Does any one have any idea what could be causing this? 

It has happened with new data and old data. It has has happened with data that has several subsets and with data that has no subsets.  

Command line truncate passwords that contain character '&'. Windows Server 2012 R2.

$
0
0

I have an application that passes the password to a batch script to invoke the BCP utility, the password contains the character '&' which is causing the command line to truncate it (up to the & character).

is there a way around this without having to change the password?

Thanks.

foreign key/table constraint

$
0
0

We import data from devices.

The first thing that is done is to insert into a header table. This table holds the serial number of the device and for each data import creates a unique id(guid).

The data is then imported into a sample table with sample time(from the device) and the unique device id. 

We want to disallow the importing of data repetitively. So we want the combination of the serial number on the header table(joined via the deviceid) and sample time to be unique.

How can this be done? It seems like it should be possible without a trigger.


Joe Garry


We have 2 SQL server 2016 servers that are having communication issues

$
0
0
We have 2 SQL server 2016 servers that are having communication issues when setting up Availability groups and replication. The servers can ping each other and can be connected using a UDL file and an ODBC connection. Port query indicates both server can reach TCP port 1433 and UDP Port 1434. TCP and NP are configured on both servers in SQL Config Mgr. The server will both ping on IPv4 but not on IPv6. Work stations donot appear to be getting any connectivity error from either machine. The error being returned between the servers is:
Cannot connect to db01-reporting.

------------------------------
ADDITIONAL INFORMATION:

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

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

A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) (Microsoft SQL Server, Error: 64)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=64&LinkId=20476

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

The specified network name is no longer available

This occurs  when trying to set up an AG replica from our Production server to our Reporting server. It also occurs when setting up replication between the 2 servers. Can create distributor on either machine and get like errors regardless of location when trying to initialize the subscription.

trying to update to odbc 17.4 but fails because it can't find the 17.3 media

$
0
0
I tried updating my sql server odbc drivers 17 and am stuck in a chicken and egg.  the previous version install msi is missing but is need for the upgrades install.  when i try to install msodbsql_17.4.1.1_x64.msi it tells me that there is a lower version and i need to upgrade, i hit "yes" -> next -> accept -> "client components" next -> Install.  it runs for a bit then gives me a "feature you are trying to use is on a network resource that is unavailable" with a pop up to find new which has the default of "C:\ProgramData\Package Cache\{175BC9FC-C256-4EFC-9D87-4A9AF3B47A12}v17.3.1.1\x64\"  which yea doesn't exist.  I can't download previous versions (or at least I haven't been able to find them on the internets) and I can't just uninstall as it wants it to.  Am i really supposed to look at the MSI manifest and remove the file and regex entries?  How am i supposed to move forward.  

Proper connection string format to access Azure SQL db using ADODB with Excel VBA

$
0
0

After 100 variations or so, and still unable to get the connection open, can someone please guide on the proper format to open and ADODB connection in Excel VBA for Azure SQL Database?

I am currently using the ActiveX Data Object 2.8 library and the SQL Native Client 12, but If that's wrong too I'd like to know.

My latest attempt is as follows

Public Function ExportExcelDataToAzureDb(wsSource As Worksheet) As Boolean
    'I am using Activex Data Object 2.8 reference, and SQL Native Client 12
    Dim connectionString As String
    Dim oConn As ADODB.Connection
    Dim record As ADODB.Recordset
    Dim cmd As ADODB.Command
    connectionString = "Driver={SQL Server Native Client 12.0};Server=tcp:myazuredbserver.database.windows.net,1433;Database=mydb;Persist Security Info=False;UID=myusername;PWD={mypass};Encrypt=yes;TrustServerCertificate=False;Connection Timeout=30;"
    Set oConn = New ADODB.Connection
    oConn.connectionString = connectionString
    oConn.Open    
    ' do work here    
    ExportExcelDataToAzureDb = True

End Function
The connection string used here is from the azure portal, with some minor modifications based on other posts Ive found


Thomas Donino Visual Studio 2010 on Windows 7

SQL JDBC upgrade from v6.0 to v7.2 causes java.lang.NullPointerException in some stored procedure returned recordsets

$
0
0

I am developing a java application onWindows 10 using Eclipse Oxygen and SQL JDBC v7.2 and java 1.8 update 202.  My code runs fine when I use SQL JDBC v6.0 (sqljdbc42.jar Jan 2017 and java 8), but gives the same java.lang.NullPointerException with SQL JDBC v7.2 (mssql-jdbc-7.2.1.jre8.jar with java 8u202) or (mssql-jdbc-7.2.1.jre11.jar with java 11.0.2) at line rs.next() or any command that attempts to access the recordset (rs) because the recordset value is null. 

(We need to upgrade to v7.2 to be compatible with java 11 as soon as possible. I have many stored procedures that run fine and two stored procedures that cause this java.lang.NullPointerException error for one recordset each in their results.   I am only including the code for one here.)

The database connection works fine and successfully returns output variables and *some* recordsets return valid results. 

The attached stored procedure gives error with JDBC v7.2 when using original complex query for recordset; it has run fine for years with JDBC v6.0.

Deploying static tables of the *same* data and revising stored procedure to reference static table works fine in JDBC 7.2.

------------------------------------
JAVA CODE:
------------------------------------

		// Create database connection and statement
		Connection con = null;

		// Establish the connection.
		SQLServerDataSource ds = new SQLServerDataSource();
		ds.setUser(strDatabaseUser);
		ds.setPassword(strDatabasePassword);
		ds.setServerName(strDatabaseServerName);
		ds.setPortNumber(intDatabaseServerPort);
		ds.setDatabaseName(strDatabaseName);

		try {
			con = ds.getConnection();
		}
		catch (SQLException se) {
			do {
				System.out.println("SQL STATE: " + se.getSQLState());
				System.out.println("ERROR CODE: " + se.getErrorCode());
				System.out.println("MESSAGE: " + se.getMessage());
				System.out.println();
				se = se.getNextException();
			} while (se != null);
		}

		CallableStatement cstmt2 = null;

		if (intArchiveID == -1)
			cstmt2 = con.prepareCall("{call dbo.selProjectTractFunding(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
		else
		{
			cstmt2 = con.prepareCall("{call dbo.selProjectTractFundingFromArchive(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
			cstmt2.setInt("ArchiveID",intArchiveID);
		}
		cstmt2.setInt("ProjectID",intProjectID);
		cstmt2.setInt("CurrentProposedFundingFY", intCurrentProposedFundingFY);
		cstmt2.registerOutParameter("LastStatusCD", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("LastFundingFY", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("curFundingAmount", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("curCostShareAmount", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("curTotalFLPCost", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("curOtherFedAmount", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("curOtherFedCostShareAmount", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("curTotalCost", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("curAcre", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("TotalFundingAmount", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("TotalCostShareAmount", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("TotalFLPCost", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("TotalOtherFedAmount", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("TotalOtherFedCostShareAmount", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("TotalCost", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("TotalAcre", java.sql.Types.INTEGER);
		cstmt2.registerOutParameter("FundingAmountToDate", java.sql.Types.INTEGER);

		boolean bCstmt2Exe = cstmt2.execute();
		ResultSet rs2=null;
		//if (bCstmt2Exe == true)
			rs2 = cstmt2.getResultSet();


		Table tblTracts = new Table(new float[]{ 6,3,5,5,5,5 });
		tblTracts.setWidth(468f);
		tblTracts.setMarginBottom(12f);
		tblTracts.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table lists all tracts in the project and their size, cost, FLP funding, Cost Share and Status." ));

		float fltCellPaddingTop=0f;
		float fltCellPaddingRight=2f;
		float fltCellPaddingLeft=2f;
		float fltCellPaddingBottom=-1f;

		Cell c1 = new Cell().add(new Paragraph("Tract Name")).addStyle(styleTableHeader);
		c1.setTextAlignment(TextAlignment.LEFT);
		c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		tblTracts.addHeaderCell(c1);

		c1 = new Cell().add(new Paragraph("Size (ac)")).addStyle(styleTableHeader);
		c1.setTextAlignment(TextAlignment.CENTER);
		c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		tblTracts.addHeaderCell(c1);

		c1 = new Cell().add(new Paragraph("Tract Cost")).addStyle(styleTableHeader);
		c1.setTextAlignment(TextAlignment.CENTER);
		c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		tblTracts.addHeaderCell(c1);

		c1 = new Cell().add(new Paragraph("FLP Funding")).addStyle(styleTableHeader);
		c1.setTextAlignment(TextAlignment.CENTER);
		c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		tblTracts.addHeaderCell(c1);

		c1 = new Cell().add(new Paragraph("Non-Fed Cost Share")).addStyle(styleTableHeader);
		c1.setTextAlignment(TextAlignment.CENTER);
		c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		tblTracts.addHeaderCell(c1);

		c1 = new Cell().add(new Paragraph("Status")).addStyle(styleTableHeader);
		c1.setTextAlignment(TextAlignment.CENTER);
		c1.setVerticalAlignment(VerticalAlignment.BOTTOM);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		tblTracts.addHeaderCell(c1);


		while (rs2.next()){
			int intTractID = rs2.getInt("TractID");
			logger.info("\nTractID: "+
					Integer.toString(intTractID));

			c1 = new Cell().add(new Paragraph(rs2.getString("TractName")).addStyle(styleTableCell));
			c1.setTextAlignment(TextAlignment.LEFT);
			c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
			tblTracts.addCell(c1);
			c1 = new Cell().add(new Paragraph(integerFormatter.format(rs2.getInt("Acre"))).addStyle(styleTableCell));
			c1.setTextAlignment(TextAlignment.RIGHT);
			c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
			tblTracts.addCell(c1);
			c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FLPCost"))).addStyle(styleTableCell));
			c1.setTextAlignment(TextAlignment.RIGHT);
			c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
			tblTracts.addCell(c1);
			c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("FundingAmount"))).addStyle(styleTableCell));
			c1.setTextAlignment(TextAlignment.RIGHT);
			c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
			tblTracts.addCell(c1);
			c1 = new Cell().add(new Paragraph(currencyFormatter.format(rs2.getInt("CostShareAmount"))).addStyle(styleTableCell));
			c1.setTextAlignment(TextAlignment.RIGHT);
			c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
			tblTracts.addCell(c1);
			c1 = new Cell().add(new Paragraph(rs2.getString("DisplayStatusFY")).addStyle(styleTableCell));
			c1.setTextAlignment(TextAlignment.CENTER);
			c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
			tblTracts.addCell(c1);
		}


		int LastFundingFY = cstmt2.getInt("LastFundingFY");
		int curFundingAmount = cstmt2.getInt("curFundingAmount");
		int curCostShareAmount = cstmt2.getInt("curCostShareAmount");
		int curTotalFLPCost = cstmt2.getInt("curTotalFLPCost");
		int curAcre = cstmt2.getInt("curAcre");
		int TotalFLPCost = cstmt2.getInt("TotalFLPCost");
		int TotalAcre = cstmt2.getInt("TotalAcre");
		int FundingAmountToDate = cstmt2.getInt("FundingAmountToDate");

		Table tblFunding = new Table(new float[]{120,60});
		float fltTableFundingCellHeight = 12f;
		tblFunding.setWidth(270F);
		tblFunding.setMarginBottom(16f);
		tblFunding.getAccessibilityProperties().addAttributes(new PdfStructureAttributes("Table").addTextAttribute("Summary","This table provides an overview of the Forest Legacy Program funding history for this project." ));

		c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Forest Legacy Program Funding").addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		c1.getAccessibilityProperties().setRole(StandardRoles.TH);
		tblFunding.addCell(c1);
		c1 = new Cell().add(new Paragraph(currencyFormatter.format(curFundingAmount)).addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		tblFunding.addCell(c1);

		c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Non-Federal Cost Share").addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		c1.getAccessibilityProperties().setRole(StandardRoles.TH);
		tblFunding.addCell(c1);
		c1 = new Cell().add(new Paragraph(currencyFormatter.format(curCostShareAmount)).addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		tblFunding.addCell(c1);

		c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Costs").addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		c1.getAccessibilityProperties().setRole(StandardRoles.TH);
		tblFunding.addCell(c1);
		c1 = new Cell().add(new Paragraph(currencyFormatter.format(curTotalFLPCost)).addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		tblFunding.addCell(c1);


		c1 = new Cell().add(new Paragraph("FY " + LastFundingFY + " Project Acres").addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		c1.getAccessibilityProperties().setRole(StandardRoles.TH);
		tblFunding.addCell(c1);
		c1 = new Cell().add(new Paragraph(integerFormatter.format(curAcre)).addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom + 10f, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		tblFunding.addCell(c1);

		c1 = new Cell().add(new Paragraph("Forest Legacy Funding To Date").addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		c1.getAccessibilityProperties().setRole(StandardRoles.TH);
		tblFunding.addCell(c1);
		c1 = new Cell().add(new Paragraph(currencyFormatter.format(FundingAmountToDate)).addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		tblFunding.addCell(c1);

		c1 = new Cell().add(new Paragraph("Total Project Costs").addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		c1.getAccessibilityProperties().setRole(StandardRoles.TH);
		tblFunding.addCell(c1);
		c1 = new Cell().add(new Paragraph(currencyFormatter.format(TotalFLPCost)).addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		tblFunding.addCell(c1);

		c1 = new Cell().add(new Paragraph("Total Project Acres").addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		c1.getAccessibilityProperties().setRole(StandardRoles.TH);
		tblFunding.addCell(c1);
		c1 = new Cell().add(new Paragraph(integerFormatter.format(TotalAcre)).addStyle(styleTableHeader));
		c1.setTextAlignment(TextAlignment.RIGHT);
		c1.setBorder(Border.NO_BORDER);
		c1.setPaddings(fltCellPaddingTop, fltCellPaddingRight, fltCellPaddingBottom, fltCellPaddingLeft);
		c1.setHeight(fltTableFundingCellHeight);
		tblFunding.addCell(c1);

		cstmt2.close();

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

STORED PROCEDURE CODE:
------------------------------------

--ORIGINAL revised by comments from Stack Overflow
/****** Object:  StoredProcedure [dbo].[selProjectTractFunding]    Script Date: 2/20/2019 3:51:35 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[selProjectTractFunding] ( @ProjectID int,
	@CurrentProposedFundingFY int, @LastStatusCD int out, @LastFundingFY int out,
	@curFundingAmount int out, @curCostShareAmount int out,
	@curTotalFLPCost int out, @curOtherFedAmount int out,
	@curOtherFedCostShareAmount int out, @curTotalCost int out,
	@curAcre int out, @TotalFundingAmount int out,
	@TotalCostShareAmount int out, @TotalFLPCost int out,
	@TotalOtherFedAmount int out, @TotalOtherFedCostShareAmount int out,
	@TotalCost int out, @TotalAcre int out,
	@FundingAmountToDate int out )

AS

	SET NOCOUNT ON
	
	declare @RC int

	select pt.ProjectID
		,t.TractID
		,t.TractName
		,t.PurchaseTypeCD
		,isnull(t.Acre,0) as Acre
		,isnull(t.FundingAmount,0) as FundingAmount
		,isnull(costshare.CostShareAmount,0) as CostShareAmount
		,(isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0)) as FLPCost
		,isnull(ofed.OtherFedAmount,0) as OtherFedAmount
		,isnull(ofed.OtherFedCostShareAmount,0) as OtherFedCostShareAmount
		,(isnull(t.FundingAmount,0) + isnull(costshare.CostShareAmount,0) + isnull(ofed.OtherFedAmount,0) + isnull(ofed.OtherFedCostShareAmount,0)) as TotalCost
		,dbo.getFY(CompleteDate) as CompleteFY
		,ts.StatusCD
		,s.Status
		,s.DisplayStatus
		,cast(case when t.CompleteDate is null then s.DisplayStatus + ' ' + cast(ts.FundingFY as varchar) else s.DisplayStatus + ' ' + cast(dbo.getFY(t.CompleteDate) as varchar) end as varchar) as DisplayStatusFY
		,ts.FundingFY
		,ts.CreatedOn
	into #temp1
	from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
	inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn	
	inner join dbo.Tract t on ts.TractID = t.TractID 
	inner join dbo.ProjectTract pt on t.TractID = pt.TractID 
	left outer join (select TractID, Sum(OtherFedAmount) as OtherFedAmount, sum(OtherFedCostShareAmount) as OtherFedCostShareAmount from dbo.OtherFederal group by TractID ) ofed on ofed.TractID = t.TractID 
	left outer join (select TractID, sum(CostShareAmount) as CostShareAmount from dbo.CostShare group by TractID) costshare on costshare.TractID = t.TractID 
	inner join dbo._refStatus s on ts.StatusCD = s.StatusCD
	where pt.ProjectID = @ProjectID
	  and ts.StatusCD <> 120 

	set @RC = @@RowCount

	-- Return recorset of tract details
	select * from #temp1 t
	order by t.TractName

	-- Get Last or Latest Status (other than closed/complete) for latest FundingFY for Project
	select top 1 @LastStatusCD = StatusCD
		,@LastFundingFY = isnull(FundingFY,0)
	from #temp1
	where not statuscd in (35,100,110,120) and FundingFY <= @CurrentProposedFundingFY
	order by FundingFY desc, StatusCD desc

	-- If LastStatusCD is null then set to 100
	if @LastStatusCD is null
		select top 1 @LastStatusCD = StatusCD
			,@LastFundingFY = FundingFY
		from #temp1
		where statuscd in (100,110) and FundingFY <= @CurrentProposedFundingFY
		order by FundingFY desc, StatusCD desc

	-- Return Subtotals for Current Status and Year
	select @curFundingAmount = sum(FundingAmount)
		,@curCostShareAmount = sum(CostShareAmount)
		,@curTotalFLPCost = sum(FLPCost)
		,@curOtherFedAmount = sum(OtherFedAmount)
		,@curOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
		,@curTotalCost = sum(TotalCost)
		,@curAcre = sum(Acre)
	from #temp1 
	where FundingFY = @LastFundingFY and StatusCD >= @LastStatusCD

	-- Return Project Totals
	select @TotalFundingAmount = sum(FundingAmount)
		,@TotalCostShareAmount = sum(CostShareAmount)
		,@TotalFLPCost = sum(FLPCost)
		,@TotalOtherFedAmount = sum(OtherFedAmount)
		,@TotalOtherFedCostShareAmount = sum(OtherFedCostShareAmount)
		,@TotalCost = sum(TotalCost)
		,@TotalAcre = sum(Acre)
	from #temp1 
		
	-- Return FLP Funding Amount To Date
	select
		@FundingAmountToDate = sum(FundingAmount)
	from #temp1
	where StatusCD >= 80 and StatusCD < 120

	-- Check for only dropped tracts
	if @RC = 0  -- this statement is true only if the first query returned no records
		begin
			select @LastFundingFY = max(ts.FundingFY)
			from (select TractID, max(CreatedOn) as CreatedOn from dbo.TractStatus group by TractID ) cs
				inner join dbo.TractStatus ts on cs.TractID = ts.TractID and cs.CreatedOn = ts.CreatedOn
				inner join dbo.ProjectTract pt on ts.TractID = pt.TractID
			where pt.ProjectID = @ProjectID
		end

	drop table #temp1

	return

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

Here is my attempt to fulfill "Guidelines when posting JDBC related questions":

Client side

  1. Which OS platform are you running on? [SQL Server 2012 on Windows 2012 with dev. client Windows 10 with java 8u202)
  2. Which JVM are you running on? java 8 update 202 (trying to eventually update to java 11.0.2)
  3. What is the connection URL in you app? Rather not share; connection not an issue.
  4. If client fails to connect, what is the client error messages? N/A, connects fine.
  5. Is the client remote or local to the SQL server machine? Remote
  6. Is your client computer in the same domain as the Server computer? (Same domain)

Server side

  1. What is the MS SQL version? [ SQL Server 2012]
  2. Does the server start successfully? [YES]
  3. If SQL Server is a named instance, is the SQL browser enabled? [YES]
  4. What is the account that the SQL Server is running under?[Domain Account]
  5. Do you make firewall exception for your SQL server TCP port if you want connect remotely through TCP provider? [YES]
  6. Do you make firewall exception for SQL Browser UDP port 1434? In SQL2000, you still need to make firewall exception for UDP port 1434 in order to support named instance.[not applicable]

Tips

  1. If you are executing a complex statement query or stored procedure, please use execute() instead of executeQuery(). [Yes, I use .execute() to execute the CallableStatement that calls the stored procedure in the database.]
  2. If you are using JDBC transactions, do not mix them with T-SQL transactions. [No we are not using transactions. Simple calls to stored procedures that return combination of output parameters and recordsets. We process the recordset information before retrieving output parameters.]

Thanks in advance for any help that you can provide me!



The format used to define the new variable for Invoke-Sqlcmd cmdlet is invalid. Please use the 'var=value' format for defining a new variable

$
0
0

I am calling a sql script from ps and passing a variable to it. 

Here is the content of zzzz.sql

select * from Translation where nTranslationID=777
print $(tempKEY)

Here is the content of zzz.ps1

$var= 'https://junkfiles.blob.core.windows.net/some-folder?sv=2019-02-02&sr=c&sig=HOtd1AorRfYtimAJY5PeVJikKiTYgcs81QeASqpXPec%3D&se=2019-11-02T17%3A42%3A01Z&sp=rw'

invoke-Sqlcmd -ServerInstance 'db1' -Database 'whatsup' -Username 'zzzzz' -Password '******' -Variable "tempKEY='$var'" -InputFile "c:\temp\zzzz.sql" -Verbose 4>&1 | Tee-Object -Variable statistics

The = signs in the variable are causing the error. Is there a way to escape the = signs ?

Thanks 

Viewing all 4164 articles
Browse latest View live


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