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

SQL Query Builder or Generator

$
0
0

Good Day!

Does anybody here know how to get all possible sql query in a given no. of textboxes automatically?I usually do to manually code it like this way for example i have 3 textboxes named textbox1, textbox2, textbox3..

if textbox1.text = "" and textbox2.text = "" and textbox3.text = "" then

'statement...

elseif textbox1.text <>"" and textbox2.text = "" and textbo3.text ="" then

'statement...

elseif textbox1.text <> "" and textbox2.text <> "" and textbox3.text ="" then

'statement...

elseif textbox1.text <> "" and textbox2.text <> "" and textbox3.text <>"" then

'statement

elseif textbox1.text = "" and textbox2.text <> "" and textbox3.text ="" then

'statement

elseif textbox1.text = "" and textbox2.text <> "" and textbox3.text <>"" then

elseif textbox1.text = "" and textbox2.text "" and textbox3.text <>"" then

'statement

.....

is there an easiest way to create an sql base on a given textboxes where the text property itself is not empty?

Sorry I'm just a newbie here and in programming..i wish someone would help me. Thank you in advance...


Cannot update a temporary table?

$
0
0

Hi,

 

I am using ADO/C++ to access SQL Server.

 

I execute the following SQL statement via ADO m_pConnection->Execute function successfully:

 

CREATE TABLE [#TempTable] (Field1 int);

 

Then execute the following SQL statement to insert data via ADO m_pConnection->Execute function successfully:

 

INSERT INTO [#TempTable] VALUES (1);

INSERT INTO [#TempTable] VALUES (0);

 

Then I execute the following SQL statement to query data via ADO m_pConnection->Execute function successfully:

 

SELECT * FROM [#TempTable];

 

So everything seems OK.

 

But when I execute the following SQL statement to update data via ADO m_pConnection->Execute function:

 

UPDATE [#TempTable] SET [Field1] = 1 WHERE [Field1] = 0;

 

I get an com error said “Object name #TempTable is invalid”.

 

That is rather strange since all my other SQL statements work properly. I also try change the table name from #TempTable to normal name TempTable in all above statements, then the UPDATE statement will work properly.

 

So what is the problem?

 

Thanks

Cannot access a temporary table?

$
0
0

Hi,

 

I am using ADO/Visual C++ to access SQL Server database. I find it is OK to create only one temp table in the database. But if I create two temp tables and open recordset of one table, and access the other table, then I will get “The object xxx is invalid” error. Below is my code:

 

#include "stdafx.h"

#include "TestTempTable.h"

 

#ifdef _DEBUG

#define new DEBUG_NEW

#endif

 

#import "msado15.dll" no_namespace rename("EOF", "EndOfFile")

 

// The one and only application object

 

CWinApp theApp;

 

using namespace std;

 

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])

{

    CoInitialize(NULL);

    try {

        _ConnectionPtr cn("ADODB.Connection");

        _RecordsetPtr rs("ADODB.Recordset");

        CString strSQLQuery;

        ULONGLONG uIndex, uCount;

        _variant_t vtFirstName;

 

        cn->Provider = "sqloledb";

        cn->Open("Data Source='(local)';Integrated Security=SSPI;", "", "", adConnectUnspecified);

 

        //  Create a test database

        strSQLQuery = _T("CREATE DATABASE MyTestDB6;");

        cn->Execute(_bstr_t(strSQLQuery), NULL, 0);

 

        //  Use the test database

        strSQLQuery = _T("USE MyTestDB6;");

        cn->Execute(_bstr_t(strSQLQuery), NULL, 0);

 

        //  Create a temp test table

        strSQLQuery = _T("CREATE TABLE #TempTable1(Field1 bigint, Field2 int, Field3 smallint, Field4 tinyint, Field5 bigint, Field6 int, Field7 smallint, Field8 tinyint, Field9 float, Field10 datetime, Field11 nvarchar(20), Field12 nvarchar(40));");

 

        if (cn->Execute(_bstr_t(strSQLQuery), NULL, 0))

        {

            //  Initialize the total test count to 5

            uCount = 5;

 

            //  Add multiple records by invoking Execute for multiple times

            strSQLQuery = _T("INSERT INTO #TempTable1 VALUES(10000, 1000, 100, 10, 20000, 2000, 200, 20, 99.98, 1920/05/20, 'Hello', 'Hello, World!');");

 

            for (uIndex = 0; uIndex < uCount; uIndex ++)

               cn->Execute(_bstr_t(strSQLQuery), NULL, 0);

 

            //  Create temp test table 2

            strSQLQuery = _T("CREATE TABLE #TempTable2(Field1 bigint, Field2 int, Field3 smallint, Field4 tinyint, Field5 bigint, Field6 int, Field7 smallint, Field8 tinyint, Field9 float, Field10 datetime, Field11 nvarchar(20), Field12 nvarchar(40));");

 

            if (cn->Execute(_bstr_t(strSQLQuery), NULL, 0))

            {

               //  Initialize the total test count to 5

               uCount = 5;

 

               //  Add multiple records by invoking Execute for multiple times

               strSQLQuery = _T("INSERT INTO #TempTable2 VALUES(10000, 1000, 100, 10, 20000, 2000, 200, 20, 99.98, 1920/05/20, 'Hello', 'Hello, World!');");

 

               for (uIndex = 0; uIndex < uCount; uIndex ++)

                   cn->Execute(_bstr_t(strSQLQuery), NULL, 0);

 

               //  Select from temp test table2

               strSQLQuery = _T("SELECT * FROM #TempTable2");

              

               if (SUCCEEDED(rs->Open(_bstr_t(strSQLQuery), _variant_t(cn, true), adOpenDynamic, adLockOptimistic, 0)))

               {

                   rs->MoveFirst();

 

                   while (!rs->EndOfFile)

                   {

                       //  Add record to temp test table 1

                       strSQLQuery = _T("INSERT INTO #TempTable1 VALUES(10000, 1000, 100, 10, 20000, 2000, 200, 20, 99.98, 1920/05/20, 'Hello', 'Hello, World!');");

                       cn->Execute(_bstr_t(strSQLQuery), NULL, 0);    // !!!!!!!!!!!!!!!!!!!Error occurs.

 

                       rs->MoveNext();

                   }

 

                   rs->Close();

               }

            }

        }

    }

    catch (_com_error &e) {

        printf("Description = '%s'\n", (char*) e.Description());

    }

    ::CoUninitialize();

}

 

Why?

 

Thanks

unsupported exception if using sqljdbc41.jar against java 6

$
0
0

According to MS doc http://msdn.microsoft.com/en-US/data/ff928484, sqljdbc41.jar and sqljdbc4.jar should support both java 6 and java 7 while in my testing, there will have unsupported exception if using sqljdbc41.jar against java 6:
: java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=com/microsoft/sqlserver/jdbc/SQLServerXADataSource, offset=6

So is it any wrong with my usage or there is document error in http://msdn.microsoft.com/en-US/data/ff928484? What I'm downloaded is the latest 4.1 drivers file sqljdbc_4.1.5605.100_enu.exe.

Login Failed!

$
0
0

I have a web app which runs fine on the server but it gives me "Login Failed" error if the same code is run on my local machine connecting to the same database server using Trusted_Connection=Yes

What could be causing the login failure?

Cannot see 'OLE DB Provider for Oracle ' in the SQL SERVER 2008 Linked Server Providers list

$
0
0

Hi,

     I am working on a X64 based Server having the Operating System..Windows Server 2008. I want to create a Linked server to a Oracle Database. After getting some information from the Internet, the first step i took care was to load 'ORACLE CLIENT SOFTWARE'. One of my Company Software group loaded the Software for me. But now when i try to create Linked server, i dont see 'OLE DB Provider for Oracle' option in the Providers list.

My question is ....Should i run some driver (If so what is the name of the driver ) with in the 'ORACLE CLIENT SERVER' to load the 'OLE DB PROVIDER FOR ORACLE' on my system.

PLEASEEE CAN SOME ONE HELP.  I AM STUCK AND I HAVE A DEADLINE TO RELEASE THE DATA IN A WEEK.

Thanks,

Vanuu

Error: Could not find or load main class when running code only on Linux Server.

$
0
0

I'm able to get a sample piece of code using Kerberos Auth to SQL working on my Windows machine.  But when I put the distribution files on the Linux server, I get the error about not able to find the load the main class.  I've tried setting the class path to the sqljdbc4.jar file and still no luck

~$ java -classpath "/users/kmcdonne/sqljdbc4.jar" -cp/users/kmcdonne jdbc6.JDBC6.jar

thanks

Kevin

How to improve ADO performance

$
0
0

Hi,

 

I am using ADO/Visual C++ 2008 to access SQL Server 2008 database.

                         

I mainly use the Execution method of the ADO connection to the SQL Server to perform the following tasks:

 

  1. Create 40000 tables by executing “CREATE TABLE …” SQL Server query.
  2. Add about 3000, 0000 records to these tables by executing “INSERT INTO …” query. In each invoke of Execute method, only one SQL statement is executed.

 

Now I find my program is very slow. And the bottleneck is the  Execution method, which takes about 90% of the total time.

 

So I want to improve the performance.

 

I have the following several strategies:

 

  1. Whether Execute method can be invoked asynchronously? If yes, then after I invoke the Execute method to submit the SQL query to SQL Server engine, before the query is executed completed, the Execute method can return and I can run other parts of the program, which will save a lot of time.

 

  1. Another solution is to merge several SQL statements together and submit them together with one invoke of Execute method. But I make a test of such a solution and find the time consumed will be longer than Executing one statement at a time. So it seems this solution is also not feasible?

 

Please tell me whether the above strategies are feasible? And whether there are more solutions for my problem.


How to Know which Access file uses particular SQL table

$
0
0

Hi,

   Sometimes sql server table gets busy and stuck. I access sql table by many access files and different remote login users. Can you anyone help me how can i find which access file using sql server particular table.

Thanks,

Ram


What is the difference between Connection.Execute and Command.Execute in ADO?

himal important sql server script

SQLSTATE 01000

$
0
0
Does anyone know how to suprime
the error message [SQLSTATE01000} that comes at the end of a Print line?
Thank you.
M.-

Strange connection issues with SQL Server named instance

$
0
0

I'm having some very strange connection issues with a named instance of SQL Server.

I have SQL Server 2012 running on a server, with the default instance and another instance named "UK" (i.e. SERVERNAME\UK).

I have another server running SQL Server 2008 R2 SSRS.

1) If I create a data source in SSRS to connect to a database on the default instance of SQL Server 2012, it works.

2) If I create a data source in SSRS to connect to a database on the named instance of SQL Server 2012:

   - Using "Windows integrated security" option, click Test Connection, it fails with the error below
   - Using "Credentials stored securely in the report server", "Use as Windows credentials" UNCHECKED (i.e. SQL authentication, using a valid SQL login/password), click Test Connection, it fails with the same error below
   - Using "Credentials stored securely in the report server", "Use as Windows credentials" CHECKED (enter a valid Windows login and password), click Test Connection, it connects successfully

Error message is "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

3) If I create a data source in SSRS like #2, use "Credentials stored securely", "Use as Windows credentials" UNCHECKED (SQL login and password) and click OK to save it, even though "Test Connection" fails with the error above, reports using the data source WORK!  It is only the Test Connection button that shows a failure.

4) I have a web application on a third server. When that web application creates a database connection (C# code, using SqlConnection() object) connects to the default instance, it works.

5) In that same web application, if I change the connection string to connect to the named instance, it fails with the error above. The connection string uses a SQL login and password, which is valid.

6) On the server running that web application, if I create an ODBC Data Source, using the named instance and the same SQL login and password, the Test button in ODBC connects successfully.

7) On the server running that web application, if I create a UDL file, and use the named instance and same SQL login and password, it also successfully connects to the server.

Therefore - it does not appear to be a login/password issue, firewall issue, and it is allowing remote connections.  But some methods will connect to the instance and some won't.  I cannot figure out why!  Any ideas??

ADODB query fails with dbnetlib connectionopen connect sql server does not exist or access denied

$
0
0

Hi folks,

I'm using the following vbscript to retrieve some values from deployment database in WindowsPE.

***************Start************

Const adOpenStatic = 3 
Const adLockOptimistic = 3 

Set objConnection = CreateObject("ADODB.Connection") 
Set objRecordSet = CreateObject("ADODB.Recordset") 

objConnection.Open _ 
    "Provider=SQLOLEDB;OLE DB Services=0;Data Source=cm01;" & _ 
        "Trusted_Connection=Yes;Initial Catalog=MDT;" & _ 
             "Network Library=DBNMPNTW;" & _ 
               "Integrated Security=SSPI;"

Dim SQL

SQL = "SELECT [DesktopOU], [LaptopOU] FROM [Settings] INNER JOIN LocationIdentity ON LocationIdentity.ID = Settings.ID WHERE Settings.Type = 'L' AND LocationIdentity.Location = 'AUS'"

objRecordSet.Open SQL, objConnection

objRecordSet.MoveFirst


'objrecordset.Fields("Name").Value
Do Until objRecordset.EOF
strDesktopOU = CStr(objRecordSet.Fields(0))
strLaptopOU = CStr(objRecordSet.Fields(1))

WScript.Echo strDesktopOU
WScript.Echo strLaptopOU

objRecordSet.MoveNext

Loop

'**********************************************************
' Set generated Task Sequence Variables
'**********************************************************

Dim TSEnv

' Connect to Task Sequence
Set TSEnv = CreateObject("Microsoft.SMS.TSEnvironment")

' Write Task Sequence Variables
TSEnv("DesktopOU") = "strDesktopOU"
TSEnv("LaptopOU") = "strLaptopOU"

*****************END********************

NamedPipes are verified and enabled, MDAC support is already provided to the media used.

Not really sure whats blocking this to work.

Confirmed SQL BRowser/SQL Server firewall exceptions at the SQL server too.

is there anything wrong in the connectingstring as the error line says about that only:

o:\VBS.vbs(9, 1) Microsoft OLE DB Provider for SQL Server:dbnetlib connectionopen connect sql server does not exist or access denied

"SQL Statement Is Not a Query" Error in Import and Export Wizard

$
0
0
Hello Everyone,

I think that I might already know the answer to my question but thought i'd ask just to get some clarification.  Here's my situation:

I have a SQL script which uses variables and a temp table to retrieve a result set.  After I ran the query and got the result set, I then started the SQL Server Import and Export Wizard and chose to export to an Excel file.  From there, I copied/pasted my SQL query into the query window and then clicked "PARSE" and it immediately fails with the error message -

"This SQL Statement Is Not a Query"

Now, my guess is that because the query is using a temp table that it cannot be parsed - am I correct?  Or, are the variables the culprit? 

Maybe both?

Does someone happen to know?

Thanks!!!

How to Restrict User to INSERT/UPDATE sensitive values in SQL Query Window even user have full permission.

$
0
0

I have scenario where the logging in user will have full permission in the database, but for a particular table colum sensitive data should not be Inserted/updated. is there any way to check this.

1. should not restrict user by providing permission bcos user will be Full Permission?

2. Trigger should not be written to handle this?

SQL Server ODBC drivers for Solaris

$
0
0

I am looking for an ODBC driver to let a Solaris box talk to a SQL Server 2012 db, I am hoping that someone will be able to put me in the right direction.

Thanks,

CB

Windows 10 client to SQL Server 2012: The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement

$
0
0

I’m an experienced.NET / SQL developer. Recently I’ve upgraded from my old 32 bit PC with Win 7 Enterprise SP1 to a new 64 bit one Win 10 Pro 15/11. Now, the old Win 7 I’m running in Hyper-V on the new PC.

My old Win 7 always was & still is well connecting to a remote SQL Server 2012 over a fast LAN-to-LAN VPN. But my new Win 10 client makes troubles when I try to connect to SQL Server using SSMS or our .NET applications:

  • SQL Server Authentication works perfectly - within some tenths of a second
  • Windows Authentication waits long and then fails on error like this:

“Connection Timeout Expired.  The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=18448; handshake=14535;  (Microsoft SQL Server, Error: -2)”

The funny thing is, thatit does not crash everytime. When I start 2 instances of SSMS side-by-side and make a try to connect (Windows Authentication) to the same server simultaneously -- IT WILL SUCCEED ! The same happens when I try to connect SSMS and our app concurrently within the same 5 or 10 seconds. So, the Windows Authentication connection is about to succeed, but not if it is running single.

According to some articles on the web I’ve experimented with LAN configuration and protocols. Now IPv6 is disabled everywhere (I hope), but the problem is still alive.

A significant problem may ley on the server side, too. It is Win Server 2008 R2 Enterprise + SQL Server 2012 Express, but the Active Directory Controller is running in the same system. It doesn’t matter for Win 7 client, but who knows, how Win 10 manages my client identity on the server in such constellation ?

I’ve spent 2 days on this problem, but my “admin” skills are short to it. Now I’m about to rewrite all app configurations to SQL Server Authentication and I feel not much happy about it…

Any ideas that could help us ?

ODBC Driver 13 (Preview) SQL Server - RedHat Linux

$
0
0

Systems requirements are only for ODBC 11 and Linux 5 or 6. Wich are for ODBC 13 and linux 7?

unixODBC 2.3.1+ (currently 2.3.4) remain unsupported on ODBC 13?

Cannot connect to SQL express instance via (local), but server name works

$
0
0

Hi all,

I have a named instance "AUTODESKVAULT" of 2014 SQL express x64 installed on a Server 2012 r2 VM. This database supports, you guessed it, Autodesk Vault, a CAD Data Managment utility. I am tring to restore a back-up of the Vault created on another server to the VM, and its unhappy and fails. I contacted support for the application in question and they had me connect to the instance from windows CMD with the command SQLCMD -E -S(local)\AUTODESKVAULT.  This Does not work, but replacing (local), with server name works fine? I think this what is hosing my restore... Any Idea's on why this might be and how to correct it?


Thanks in advance,

Tom


Viewing all 4164 articles
Browse latest View live


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