Tag Archives: SQL Server

[Solved] Pyodbc.ProgrammingError: No results. Previous SQL was not a query.

Call the stored procedure on the remote sqlserver server with Python. Code fragment:


    conn = pyodbc.connect(SERVER=host, UID=user, PWD=password, DATABASE=dbname,
                            DRIVER=driver)
    cur = conn.cursor()
    if not cur:
        raise (NameError, 'Database connection error)
    else:
        cur.execute("EXEC GetLastData")
        resList = list()
        resList = cur.fetchall()

Execution error:

pyodbc.ProgrammingError: No results.  Previous SQL was not a query.

After checking, the stored procedure can be executed normally in the sqlserver environment. It seems that there is a problem when calling pyodbc. A similar problem is found on stackoverflow. The answer is as follows:
the problem was solved by adding set NOCOUNT on; to the beginning of the anonymous code block. That statement suppresses the record count values generated by DML statements like UPDATE … and allows the result set to be retrieved directly.

The problem is solved by adding it to the beginning of the anonymous code block. This statement suppresses the record count value generated by the DML statement and allows the set result to be retrieved directly. SET NOCOUNT ON; UPDATE …

So add a sentence set NOCOUNT on to the stored procedure

CREATE proc [dbo].[GetLastData]
AS
BEGIN

SET NOCOUNT ON

declare @begindate datetime,@enddate datetime
select @begindate=CONVERT(varchar(7),GETDATE(),120)+'-01'
select @enddate=DATEADD(MONTH,1,@begindate)

How to Solved Error: 18456, Severity: 14, State: 38.

If you have installed Windows SharePoint 3.0, “Error: 18456, Severity: 14, State: 38”, caused SQLSERVERAGENT does not start.

Set start mode for SQL Server Agent to automatic, fix this problem

I also encountered the Error 18456 Sev 14 State 16 on our MS Sql Server. At first i try to reset the password for my user but i have no success. But when I try again to look at the users properties having the error i found out that there is no default database assign for that user. I just assign a database and presto I can log on to my database.

My Slotuion:

1. Log on using sa account.

2. Expand secuirity and logins.

3. Right click on the user account with login problem problem and choose properties.

4. On properties genral tab, you will see an drop down option for default database used for the account, choose a database for the account to used and click ok or apply then ok.

5. Log off on sa account and try to log in again.

That solution works for me.

Solution to “[dbnetlib] [connectionwrite (send()).] general network error”

Recently, I need to use Excel to generate a series of charts, the data is naturally obtained through sql server. The problem is that this excel has nearly 50 charts, and each chart has to be connected to DB to get the data. The problem comes, when refreshing all the time often encountered
“[DBNETLIB] [ConnectionWrite (send()). General network error. Check your network documentation” error. The initial judgment is definitely too much data connection caused by (for Excel rookies do not have the ability to solve from the Excel side). After a while Google, finally found a solution, maybe not the best, right as a record.

Possible causes.
This problem occurs because Windows Server 2003 and higher implements a security feature that reduces the size of the queue of concurrent TCP/IP connections to the server. This feature helps prevent denial-of-service attacks. Under high load conditions, the TCP/IP protocol may incorrectly recognize a valid TCP/IP connection as a denial-of-service attack. This behavior can lead to the problems described in the Symptoms section.

Solution.
This section, method, or task contains steps that tell you how to modify the registry. However, serious problems can occur if the registry is not modified correctly. Therefore, make sure you follow these steps carefully. For extra protection, back up the registry before modifying it. Then, if a problem occurs, you can restore the registry.
To resolve this issue, turn off this new feature by adding SynAttackProtect entry to the following registry entry for the computer that is running Microsoft SQL Server, which houses your BizTalk server database.

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Tcpip \ \ Service Parameters

Settings

SynAttackProtect

Enter a DWORD value of 00000000. to do this, follow these steps:
Click Start, click Run, type regedit, and then click OK. Find and click on the following registry entry:

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Tcpip \ \ Service Parameters

On the Edit menu, point to New, then click on the DWORD value. Type SynAttackProtect, and then press ENTER. Click Modify on the Edit menu. In the Value Data box, type 00000000. click OK. exit the Registry Editor.
Note To complete this registry change, you must restart the computer running SQL Server.

 

Unable to open the physical file “d:\***.mdf”. Operating system error 5: “5(Access is denied.)”.

SQL SERVER2008 is installed under Windows 7. An error occurred trying to attach an existing database MDF file,
Unable to open the physical file “d:\***.mdf”. Operating system error 5: “5(Access is denied.)”.
Is to set the SQL Server related account access to the file
Let Management Studio run as an administrator
 

Error converting data type nvarchar to datetime

Today I wrote a stored procedure that executes with the current time as a parameter to the stored procedure, causing a number of problems.

See the original notation
Error. SQL error
Startsyntax near ‘)’ because the function cannot be used as a parameter to the stored procedure. Modified to
In SQL, you assign the return value of the getDate () function to a variable, and then assign it to the stored procedure variable. This error is resolved.

      

USE [TransferLog]
GO

DECLARE	@return_value int,

        
EXEC	@return_value = [dbo].[SSISLog_InsertQCTransferLog]
        @StartDate = getdate(),
		@LogCategoryId = 2,
		@AffectRows = '',
		@QCLastModifiedDate = N'''',
		@ErrorMessage = N'',
		@MaxAuditLogId = '',
		@MaxAuditPropertyId = ''


SELECT	'Return Value' = @return_value
SELECT CONVERT(datetime, GETDATE(), 120) AS Date
GO
USE [TransferLog]
GO

DECLARE	@return_value int,
        @timee datetime=getdate()
        
EXEC	@return_value = [dbo].[SSISLog_InsertQCTransferLog]
        @StartDate = @timee,
		@LogCategoryId = 2,
		@AffectRows = '',
		@QCLastModifiedDate = N'',
		@ErrorMessage = N'''',
		@MaxAuditLogId = '',
		@MaxAuditPropertyId = ''

SELECT	'Return Value' = @return_value
select @timee
SELECT CONVERT(datetime, GETDATE(), 120) AS Date
GO

But there it is again
The Error converting Data type, nvarchar to datetime, always thought that the Error converting type is still the wrong thing to assign to @startDate. I get a lot of replies on the Internet that say CONVERT(datetime, GETDATE(), 120) conversion type
The type of @qclastModifiedDate is also datetime, but in
Error.sql, I gave it a value
@QCLastModifiedDate=N””

After changing @qclastModifiedDate =N “, the error is gone. The database QCLastModifiedDate was written to the default value ‘1900-01-01 00:00:00 00.000’.

Right at last. True. SQL is the correct script after modification. I really need to be careful

Arithmetic overflow error converting identity to data type int

This is a real problem in the project, resulting in the final collapse of all projects! It took two hours to figure out the problem
Background: All of a sudden before I went to work in the morning, I was told that the lights of all the projects could not be turned off normally. Oh, my god, this can’t happen. This has never happened before. Hurry to the company, first with the preparatory plan to all equipment to send instructions to shut down. Then start looking for problems.
Procedure: I initially thought there was a problem with either the server or IIS, because IIS often died at regular intervals and needed to be restarted. But obviously not this time, because the site is accessible. Then check the service. After checking for a long time, I found that there was a code error. It was just a simple statement to update the database.
Update XXX set XX = X where XXXX = XXXX
The following statement returns the Arithmetic overflow error IDENTITY to data type int
Although English is not good, but you can see that the conversion type is wrong, the conversion type int is wrong, the primary key identifies the column, overflow. But I’m sure this statement will be fine, but I still want to have a trigger after this table is updated. So look at the trigger, and there’s a job to insert into another table, and look at that table whose primary key is an int. Suddenly I understood, because the table will store tens of thousands of data a day, although it will be emptied regularly, but the self-growth ID will increase. So id is greater than 200 million, which is 2 to the 32nd power.
Solution: Change the field type to bigint or VARCHar (GUID). Bigint is also limited, but in theory it should be fine!

SQL 2005 remote connection error (provider: SQL network interface, error: 28 – the server does not support the requested protocol

Solution: On the server side: Open SQL2005 SQL Server Management Studio program
(1) to connect to the database,
(2) trying to choose the registered under the menu Server
if there are no things out of the window, to update the local Server database engine right click on the select register
(3) on the local hope remote access database, right click on the select SQL Server configuration manager
(4) in the window, Select SQL Server 2005 network configuration in the left tree, select the appropriate database in the sub-set,
(5) and right click on TCP/IP in the right protocol to enable it
I followed this method to do first, and then found that it was still unable to connect to the server, finally use the following method to solve: start — “program –” Microsoft SQL Server 2005–& GT; SQL Server 2005 Peripheral Application Configurator select “Peripheral Application Configurator for Services and Connections” in this SQL server instance select Database Engine -& GT; For remote connections, select both TCP/IP and Named Pipes in the box on the right for local and remote connections

SQL Server 2005, unable to log in, forget sa password, 15405 error!


can not be connected to./SQLEXPRESS.
Additional information:
user ‘sa’ login failed. This user is not associated with a trusted SQL Server connection. (18452), Microsoft SQL Server Error:)
— — — — — — — — — — — — — — — — — —
it’s mapping times wrong:
failed to create for user “sa”. (Microsoft) is essentially) express. The smo)
Additional information:
perform Transact_SQL statements or abnormal happened when the batch. (Microsoft) is essentially) express. ConnectionInfo)
unable to use special groups’ sa ‘. The (15405), Microsoft SQL Server Error:

2, the concrete solving steps:

the first step: open the SQL2005 with administrator login first, then right-click the selected attributes in the service name & gt; Security & gt; The login mode option on the right has been changed to authentication OK!

step 2: select safety (expand)> Login name & gt; Double-click the sa> Password change the password you need to confirm! Then turn off SQL2005 or disconnect.

. Step 3: start > Application & gt; Choose SQL2005 & gt; Configuration tool & GT; Open the configuration manager> Expand SQL Server2005 network configuration
note: select MSSQLSERVER if SQMEXPRESS
> TCP/IP options & gt; Enable and right click > Property & gt; Ip address TAB & GT; Change all disabled options to enabled & GT; Then restart the SQL2005 service!

Version problem of SQL Server


Recently, SQL Server 2005 has been installed on the computer. It works normally on this computer. Everything is OK.

When connected to the server operation Database, however, you Unspecified error when creating the table:

The details of the error are as follows:

===================================


Unspecified error
 (MS Visual Database Tools)


------------------------------
Program Location:


   at Microsoft.VisualStudio.DataTools.Interop.IDTTableDesignerFactory.NewTable(Object dsRef, Object pServiceProvider)
   at Microsoft.SqlServer.Management.UI.VSIntegration.Editors.TableDesignerNode.CreateDesigner(IDTDocToolFactoryProvider factoryProvider, IVsDataConnection dataConnection)
   at Microsoft.SqlServer.Management.UI.VSIntegration.Editors.VsDataDesignerNode.CreateDesigner()
   at Microsoft.SqlServer.Management.UI.VSIntegration.Editors.VsDataDesignerNode.Open()
   at Microsoft.SqlServer.Management.UI.VSIntegration.Editors.VirtualProject.Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ISqlVirtualProject.CreateDesigner(Urn origUrn, DocumentType editorType, DocumentOptions aeOptions, IManagedConnection con)
   at Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ISqlVirtualProject.CreateDesigner(Urn origUrn, DocumentType editorType, DocumentOptions aeOptions, IManagedConnection con)
   at Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptFactory.CreateDesigner(DocumentType editorType, DocumentOptions aeOptions, Urn parentUrn, IManagedConnection mc)
   at Microsoft.SqlServer.Management.UI.VSIntegration.Editors.VsDocumentMenuItem.CreateDesignerWindow(IManagedConnection mc, DocumentOptions options)

=========================================

checked on the Internet, the original problem was between SQL Server versions: SQL Server 2005 Management Studio could not operate SQL Server 2008, so this error occurred.

The solution is to replace 2005 with 2008.

JDBC connect to Sql Server to connect to the database–The TCP/IP connection to the host localhost, port 1433 has failed

Have you ever made such a mistake?

The TCP/IP connection to the host localhost, port 1433 has failed.

com.microsoft.sqlserver.jdbc.SQLServerException: 
The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. 
Verify the connection properties.
Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. 
Make sure that TCP connections to the port are not blocked by a firewall.".

Solutions:
1. Select the computer – & GT; Right click management – & GT; Computer management — & GT; Service and application
(1) first check SQL server service whether
has been enabled to — > SQL Server configuration Manager — & GT; SQL Server service, make sure local SQL Server service is enabled.

(2) then check SQL server network configuration
to — > SQL Server configuration Manager — & GT; SQL Server network configuration ensures that the Named Pipes and TCP/IP protocols are enabled.


2. If we run the program again, it may appear that the connection is still unsuccessful, so we can continue to solve the problem:
or code> SQL server network configuration
to — > SQL Server configuration Manager — & GT; SQL Server network configuration, Named Pipes and TCP/IP protocol is enabled, select TCP/IP right click – > Property – & gt; IP address, scroll down to see if IPALL in TCP port is 1433, no, then change to 1433.

finally, restart SQL Server service, then run the program again, successful, comfortable!