In chapter 2 of Microsoft Press' "Inside Microsoft SQL Server 2005 - T-SQL Querying", an example showing how to use dynamic management view sys.dm_exec_query_optimizer_info begins with the following code:
SET NOCOUNT ON; USE Northwind; -- use your database name here DBCC FREE PROCCACHE; -- empty the procedure cache GO
When I copy, paste and execute this query, I get the message:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'PROCCACHE'
How can I correct the syntax?
PS. The rest of the example seems to run properly even without the DBCC FREE PROCCACHE line.
DB-Library Error 10007: General SQL Server error: Check messages fromthe SQLServer.CREATE PROCEDURE [dbo].[spu_Import_Export_Image](@srvr varchar(50),@db varchar(50),@usr varchar(15),@pwd varchar(50),@tbl varchar(50),@col varchar(50),@mod varchar(1),@imgpath1 varchar(1000),@pk varchar(50))ASBEGINdeclare @path varchar(50)declare @whr varchar(200)declare @fil varchar(100)declare @cmd varchar(1000)declare @imgpath varchar(800)declare @ext varchar(5)--declare @pk varchar(50)declare @KeyValue varchar(8000)declare @image varchar(50)--declare @imgpath1 varchar(1000)declare @imgpath2 varchar(1000)declare @sellist varchar(2000)set @path = 'c: extCopy.exe'select @sellist = 'DECLARE curKey CURSOR FOR SELECT ' + @pk +' FROM '+ @tbl + ' ORDER BY ' + @pkexec (@sellist)OPEN curKeyFETCH NEXT FROM curKey INTO @KeyValueWHILE (@@fetch_status = 0)BEGINset @whr = '"where '+ @pk +' = "' + @KeyValueset @fil = @imgpath1 + '' + @KeyValue --+ @extset @cmd = @path + ' /S ' + @srvr + ' /D ' + @db + ' /U ' + @usr+ ' /P ' + @pwd+ ' /T ' + @tbl + ' /C ' + @col + ' /W ' + @whr + '/F ' + @fil+ ' /' + @modexec Master..xp_cmdShell @cmdFETCH NEXT FROM curKey INTO @KeyValueENDCLOSE curKeyDEALLOCATE curKeyENDGOAbove srcipt runs fine with image data type in one table but when irun for some other table it gives me Error MessageTEXTCOPY Version 1.0DB-Library version 8.00.194SQL Server 'WSQL01' Message 170: Line 1: Incorrect syntax near '99'.(Concerning line 1)DB-Library Error 10007: General SQL Server error: Check messages fromthe SQLServer.ERROR: Could not use database 'test1'NULL-----------Aslo it only runs on server console if i run it from workstation uingsame files and tables it gives me an error again. Can anybody help meand reply me at Join Bytes! asap.thnx,dharmesh
my aspnetdb.mdf can,t created my remote connection settings in sql server is ok and i get this folwing error :
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. SQLExpress database file auto-creation error: The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist. If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database. Sql Server Express must be installed on the machine. The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts. Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[SqlException (0x80131904): An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +115 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346 System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +1093 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +1083 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +272 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +351 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +90 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +115 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +122 System.Data.SqlClient.SqlConnection.Open() +227 System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +110
I tried to replicate between SVRPOS01 and SVRPOS02. SVRPOS01 is publisher and distributor. Replication is Merge replication. But, after snapshot agent ran, the following error comes out and merge agent doesn't do merge replication. When configure replication I choose option initialize schema.., and in SVRPOS02 I just create empty DB. Most of time this works... but not in this time.. SVRPOS02 doesn't have data replicated... Please reply any idea of following error, and solution if you have any.. Thank you.
<Error message> The schema script '\SVRPOS01C$Program FilesMicrosoft SQL ServerMSSQLReplDatauncSVRPOS01_POS_POSPublicat ion20040706003309v_Item_Old_232.sch' could not be propagated to the subscriber.
<Error Detail> The schema script '\SVRPOS01C$Program FilesMicrosoft SQL ServerMSSQLReplDatauncSVRPOS01_POS_POSPublicat ion20040706003309v_Item_Old_232.sch' could not be propagated to the subscriber. (Source: Merge Replication Provider (Agent); Error number: -2147201001) --------------------------------------------------------------------------------------------------------------- Unable to replicate a view or function because the referenced objects or columns are not present on the Subscriber. (Source: SVRPOS02 (Agent); Error number: 0) --------------------------------------------------------------------------------------------------------------- Invalid object name 'POSLOC.dbo.BARCODE_MATCH'. (Source: SVRPOS02 (Data source); Error number: 208) ---------------------------------------------------------------------------------------------------------------
We have a report where we do a whole bunch of calculations.
Sometimes we get #div0 err,when you try to divide a number by 0, or NaN Error, when you are trying to divide 0 in the numerator.. Is there a tool, that can sopt check these errors on a report in reporting services, and generate a log that we can check daily for errs?Pl advise
select ClaimNumber, Surname, FirstName, CASE WHEN New= 0 THEN 'Yes' ELSE 'No' END AS Processed
from EntryTable) Select * from ProcessedYesNo Where Ignore_dupe='Yes';
why I am getting an syntex error I check the query it is ok atleast the inner query is running but when I apply the with than I am getting Syntax error near 'WITH'
I just this day started using SQL sever 2005. I created a database and then created a table. Then I started adding some fields. I wanted to add a check constraint to one of the fields called state but I keep getting the same error. I right click on the field while editing the table and select check constraint. I then click add on the check constraint dialogue and in the expression caption I input the following:
<code>
@State In('CA', 'AZ', 'UT', 'CO')
</code>
I am using a book and have straight copied the above example from the book. However when I input the check constraint I get the following error;
"Error validating constraint 'ck_myfirstdatabase'
I have tried this with other fields and other types of check constraints and I still get the same error. I have tried to delete the database and recreate it. I have tried everything I can think of and I cannot seem to get check constraints to work. I have no idea why I keep getting this message. I have checked the examples a thousand times, the syntax is definately correct. This is getting extremely annoying as I cannot continue unless I do this. I'm all out of ideas. Can anyone please tell me why it could not be working? Any ideas would be greatly appreciated.
I ran the below INSERT COMMAND and it resulted into the following error message.You can also see the table structure below.Those are the only two tables that reference the Artist table.
SET IDENTITY_INSERT dbo.ARTIST ON INSERT INTO ARTIST (ArtistID,LastName,FirstName,Nationality,DateOfBirth,DateDeceased) VALUES(1, 'Miro', 'Joan', 'Spanish', 1893, 1983);
I am using a foreach file to loop through a folder and pick a file. Then populate a Sql table.
Now I want to check if the file is a mdb and then check if the mdb contains a table called "Schools". If any of these conditions fails, the file should be moved to the Error folder. If conditions pass, populate the Sql tables.
How do I do this? Please specify the components to use.
I am currently using VWD. I only run my web applications with the Cassini. However, as long as I want to hardcode with SqlConnection object, an error occurs. I did a little bit modification to the following codes which use SqlConnection and was quoted from the book "Professional ASP.NET 2.0", Wrox. <%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Configuration" %> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Not Page.IsPostBack Then Dim MyConnection As SqlConnection Dim MyCommand As SqlCommand Dim MyReader As SqlDataReader MyConnection = New SqlConnection() MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDB").ConnectionString MyCommand = New SqlCommand() MyCommand.CommandText = "SELECT TOP 3 * FROM Paspnet_Users" MyCommand.CommandType = CommandType.Text MyCommand.Connection = MyConnection MyCommand.Connection.Open() MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection) gvCustomers.DataSource = MyReader gvCustomers.DataBind() MyCommand.Dispose() MyConnection.Dispose() End If End Sub </script> <html> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="gvCustomers" runat="server"> </asp:GridView> </div> </form> </body> </html> The error: System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object." Source="App_Web_v1u8yf_l" StackTrace: at ASP.sqlconnectiontest_aspx.Page_Load(Object sender, EventArgs e) in F:My DocumentMy StudySITMT4Introduction to ASP.NetMeowMeowShoppingCartSQLconnectionTest.aspx:line 13 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) Please help me find out what's the problem. Thanks beforehand.
Just wondering what would be the normal or more efficient practice to insert/update a record.
1. Check for existence of primary record (using SELECT in stored procedure) 2. Capture error and handling
My problem is that I try to execute an stored procedure from a VB client.. but unable to capture the errors in SP, it just prompts the error and thats it, not responding to my "SELECT @err = @@ERROR" after the insert statement.
so now, I'm thinking of capturing the error on the client (which I am able to do) and handle it from there.. or to make sure that RI is enforced by 'searching' for Pks in the primary tables before executing the INSERT statement in my stored procedure.
I am getting "General network error. Check your documentation." I am using .net 1.1 to connect sql server 2005 database at remote place. .net code is running on windows xp and database(Dev database) is running on windows 2003 server. below is my code.
conn = new SqlConnection("Persist Security Info=False; User ID=xxx; Password=pwd; database=WBWT; server=machinename; Connect Timeout=300; Max Pool Size=10"); conn.Open(); cmd = conn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure ; cmd.CommandText = "TestForCollation"; SqlParameter param1 = new SqlParameter("@MESSAGE",SqlDbType.NVarChar, 100); param1.Value= "Dhanaji"; param1.Direction = ParameterDirection.Input; cmd.Parameters.Add( param1 ); SqlParameter param2 = new SqlParameter("@CATEGORY",SqlDbType.Char, 10); param1.Value= "Patil"; param1.Direction = ParameterDirection.Input; cmd.Parameters.Add( param2 ); adapter = new SqlDataAdapter((SqlCommand)cmd); adapter.Fill(ds); // here it throws exception
When i use VARCHAR data type or Output parameter in stored procedure it gives this error. For the stored procedure which has not any parameter or only input int parameter is executed sucessfully, Same SP is excuted sucessfully on local machine. I need urgent help
Also same code works on another database at remote place(QA database)
i need the t-sql statement for a check constraint that has a custom error message that shows the proper fromat for column entry.... i know its confusing...
example... if im using the authors table in the pubs database and the numbers in the au_id column reads xxx-xxxxxx where x represents numbers... what must i do so that the error message reads the proper format... ie. use proper format XXX-XXXXXX, is what i might want the error message to read.
Hi,I am getting the following error (When i am trying to update the column thru windows service) Please let me know the solution for the following.The following error is comming only when i set CommandTimeout to infinity (Commandtimeout=0).General network error. Check your network documentation. Number 11 Procedure ConnectionRead (recv()). Class 20 State 0 Source .Net SqlClient Data Provider Server Line number 0 Thanks and Best RegardsNagaraju A
I want my users to submit there email address and username to my Sql Database, but i want to prevent them from adding already existed usernames to my table.
I have a usernametextbox and emailtextbox and a Submit button. How do i check in my table before Submiting?
I met a very strange problem recently. I set up a database integrity check maintenance plan. But this job failed every time. I looked into the logs, the error message was that Databases that have a compatibility level of 70 (SQL Server version 7.0) will be skipped. I used the sp_helpdb to check the version of the databases included in my maintenance plan. The sp result shows that all the databases are above version 80....
Even more strange, i can successfully run the dbcc check query on each database.
Any comment and suggestion will be very appreciated.
Hi, guys I try to add some error check and transaction and rollback function on my insert stored procedure but I have an error "Error converting data type varchar to smalldatatime" if i don't use /*error check*/ code, everything went well and insert a row into contract table. could you correct my code, if you know what is the problem?
thanks
My contract table DDL: ************************************************** ***
create table contract( contractNum int identity(1,1) primary key, contractDate smalldatetime not null, tuition money not null, studentId char(4) not null foreign key references student (studentId), contactId int not null foreign key references contact (contactId) );
My insert stored procedure is: ************************************************** *****
create proc sp_insert_new_contract ( @contractDate[smalldatetime], @tuition [money], @studentId[char](4), @contactId[int]) as
if not exists (select studentid from student where studentid = @studentId) begin print 'studentid is not a valid id' return -1 end
if not exists (select contactId from contact where contactId = @contactId) begin print 'contactid is not a valid id' return -1 end begin transaction
/*Error Check */ if @@error !=0 or @@rowcount !=1 begin rollback transaction print ‘Insert is failed’ return -1 end print ’New contract has been added’
I have a field 'Rowguid' of type uniqueidentifier in a table. This field is the last field in the table. In this case if I update a record through the application I don't get any error. Suppose if there are additional fields after the field Rowguid I get the error "Multiple-Step operation cannot be generated Check each status value"
For your reference I have used the following statement to add the RowGuid field
Alter table <tablename> Add RowGuid uniqueidentifier ROWGUIDCOL NOT NULL Default (newid())
I have been searching for a means to change the System Failure Error Check policy that comes as part of the Best Practice policies. I want to look back 24 hours. The WQL query shipped with the policy doesn't have a WHERE clause component that looks at TimeGenerated. That query looks like:
IsNull(ExecuteWql('Numeric', 'rootCIMV2', 'select EventCode from Win32_NTLogEvent where EventCode=6008 and Logfile="System"'), 0)
After searching for an example of how to do this and not finding any that are specific to PBM, I decided to fall back to a very basic approach - use wbemtest.exe to try out where clause additions and see how they work, then plug the result into the policy and see if it works. As a start, I tried the following query using wbemtest.exe:
select Event Code from Win32_NTLogEvent where EventCode = 6008 and Logfile = 'System' and TimeGenerated > '20130101010000.000000–000'
This works great in wbemtest.exe. My next step was to plug this into the policy condition expression as follows: IsNull(ExecuteWql ('Numeric', 'rootCIMV2', 'select EventCode from Win32_NTLogEvent where EventCode=6008 and Logfile="System" and TimeGenerated > "20130101010000.000000–000"'), 0)
When I try to manually evaluate this policy in SSMS, I receive an "Invalid Query" error message.I assume that SWbemDateTime isn't available to use inside Policy Based Management policies. All the examples of how to handle the kind of dynamic date creation I have seen are for use in PowerShell, VBScript, or SSIS. I've played with using DateDiff, DateAdd, and GetDate inside the query string, with no success.
Why does the ExecuteWql above fail?Is it at all possible to dynamically generate a datetime (say, 24 hours ago) as part of the query string parameter of the ExecuteWql call?What might that look like?
I wanted to create a package to copy the objects from one database to another and replace those object if they already exist. Therefore, before the package executes you do not know whether all the objects exist on the target server or only some of them.
Using the 'Transfer SQL Server Objects Task' I have found that I cannot get this to execute cleanly by itself. If I set the 'DropObjectsFirst' to false then an error is thrown if the object exists and if I set it to true then an error is thrown if it does not exist.
In order to get round this I have had to create an 'Execute SQL Task' to list all the objects and then go through them dropping them on the target server in a for each loop before executing the 'Transfer SQL Server Objects Task' with 'Transfer SQL Server Objects Task' set to false.
However, is there a better way of achieving this or am I missing something in the 'Transfer SQL Server Objects Task'?
I am using ATL COM library application. It is using sql data base for fetching the records. Some times, i get the following error. could you please let me know, why this happens? This is not reproduceble every time.
(Error! hr=80040e21, hrDesc=Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work
Here is the code to connect to database which i am using.
I would like to make sure that SQL Server Express is completely free even for public institutions e.g. bailiff office. We (my office) want to use SQL Server Express 2005 at 9 computers for free, is it possible? Can you give me a full answer? Thanks!
Surely not everyone that uses SQL on a shared server has to buy their own copy of SQL Server?
Is there a free utility to copy it from the host to local? I am assuming that SQL management express can not do this (after searching the help for a while... annoying)
We have a Windows 2003 Web Edition server serving a site through IIS. It connects to a Windows 2003 Standard Edition server running SQL 2000 SP3a.
This site receives the following error as seen in the topic: [DBNETLIB][ConnectionRead (recv()).]General network error. Check your network documentation.
We've configured the server network utility to only allow TCP/IP connections. The connection string for the site is as follows:
Any ideas or tips on solving this issue? We've noticed it is due to larger queries as smaller ones do work with no problems.
The servers are behind a BSD box running iptables, has 1433,1434 along with standard web ports wide open. Anything outbound is allowed.
Some further testing via ODBC on the IIS server improved things. No more connection pooling for the SQL Server driver allows for 1/3 of the query to run. Still 2/3s of it doesn't show up, and that general network error message appears.
Hi While running a DTS, many times the error message: "[DBNETLIB][ConnetionWrite (WrapperWrite()).]General network error. Check your network documentation." appears. Does somebody knows why?
I am running the DTS from a computer (not the server where the DTS is stored) and it is connected without any problem when this happens.
My application is running fine, as i can login to it and also able to view pages. But when i open Order management(having 3K records) its give me error,
General Network Error. Check your network documentation
I have also searched many articles and tried following solutions but nothing working
- connectiontimeout = 0, max pool size = 7500/100, pooling = false
- SSL disabling enforce security false as mentioned in microsoft kb article.
And there's nothing any issue with hardware/firewall as my application's login and other forms are working fine(which use same database with same connection string)
I'm executing a stored procedure, before execution the memory used for sqlservr.exe in the task manager reflects about 50mb. but after the stored procedure is executed, the memory used by sqlservr.exe boosts up to 200mb and remains at 200mb even after execution. this causes my pc to slow down. how dow i reset the memory used by sqlservr.exe after executing the stored procedure? any help will be very much appreciated. thank you.