SqlConnection, SqlClient Codes Underlined In My Connectionstring Defined
Aug 9, 2005
Somebody should please render me some VB.NET codes for implementing an add button click event to add record to my SQL Table from my web form in asp.net application running on my local machine. I am not here with my connection string codes from which the error exists.
View 1 Replies
ADVERTISEMENT
Mar 14, 2007
Is "Encrypt" not support in Compact Framework 2.0 SqlConnection string?
Trying to connect to sql2005 db using SSL from WM5/.net 2.0 pda and am receiving the below error. I can connect fine w/o the "encrypt" argument and the same connection string with "encrypt" connects fine from XP workstation to sql db w/SSL.
"Unknown connection option in connection string: encrypt."
Connection String I used:
sqlConnection = new SqlConnection("Data Source=mysqlserver;Initial Catalog=sometable;UID=username;PWD=Password;Encrypt=true;");
Thanks,
Jim
View 9 Replies
View Related
May 3, 2008
<code>
public static DataTable GetCountries() { SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["omegaloveConnectionString"]);
if (myConnection.Connect()) .............. problem
{ SqlCommand cmd = new SqlCommand("prcGetCountries", myConnection); cmd.CommandType = CommandType.StoredProcedure; DataTable countries = new DataTable(); countries.Columns.Add("CountryId", typeof(string)); countries.Columns.Add("Country", typeof(string)); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { DataRow dr = countries.NewRow(); dr[0] = reader["CountryId"].ToString(); dr[1] = reader["Country"].ToString(); countries.Rows.Add(dr); } reader.Close(); return countries; } else return null; } }
</code>
View 1 Replies
View Related
Apr 23, 2007
I have lots of problems with the connection. I've connected many dropdownlists to the database and i didn't have problems at all. I also try an example of an ASP.NET book:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString= "<%$ ConnectionStrings:CIPPEC%>"
InsertCommand=
"INSERT INTO
[member] ([first_name], [last_name], [malefemale], [yearborn])
VALUES
(@first_name, @last_name, @malefemale, @yearborn)">
<InsertParameters>
<asp:FormParameter Name="first_name" Type="String"
FormField="FirstTextBox" />
<asp:FormParameter Name="last_name" Type="String"
FormField="LastTextbox"/>
<asp:FormParameter Name="malefemale" Type="Int32"
FormField="MFRadioButton" />
<asp:FormParameter Name="yearborn" Type="Int32"
FormField="YearDropDown" />
</InsertParameters>
</asp:SqlDataSource>
And it worked well. But when i try to connect my page with:
Dim connect As New Data.SqlClient.SqlConnection( _
"Server=glgrand-arSQLEXPRESS;UID="WindowsStartupUser";password="WindowsStartupPass"; database=CIPPEC")
connect.Open()
Dim cmd As New Data.SqlClient.SqlCommand( _
"INSERT PRUEBA (PersonaJuridica, NombreRazonSocial, Nombre, Segundo_nombre, Apellido) " & _
"VALUES (txtPerJur, txtRazSoc, txtName, txtSecondName, txtApellido)", _
connect)
cmd.ExecuteNonQuery()
connect.Close()
The error message says: Login failed for user 'username'.
I tried lots of things but it didn't work:
In SQL Configuration Manager:
Client Protocols: TCP/IP and Named Pipes are enabled.
In SQL 2005 Services: Server Properties: Built-in Account: Local System
SQL Server Surface Area Configuration: Remote connections: Using both TCP/IP and Name Pipes connection is selected.
In SQL Management Studio i created a new login glgrand-ar/UserStartupName , with sysadmin server role and user mapping my CIPPEC database.
I don't know what else i could try, i tried it at home and at work and i couldn't connect to my database and make an INSERT. It stops at Connect.Open() with the error that i wrote in this subject message.
It's evident that i'm doing something wrong (because i'm new): Could you please help me with a solution and explain me what are the data that i have to put on the Data.SqlClient.SqlConnection ?? I'm using the Windows authentication: i'm putting my username and password and it doesn't worked.
Thank you!!
View 1 Replies
View Related
Sep 19, 2007
Hi all.I am using VB.Net 2002 (.Net Framework 1.0) and Sql Server 2005 Express Edition as a database. I am following a tutorial to create a connection to a database.I have written this code to import namespaces at my .aspx file. <%@ import namespace = system.data%><%@ import namespace = system.data.sqlclient%>And, I also put this code at my Page_Load event that resides at .aspx.vb file. Dim conn As sqlConnection conn = New sqlConnection("server=SEN-M092082D001SQLEXPRESS;database=test;Trusted_Connection=Yes") conn.open() lblItem.Text = "Connection Opened!" Those codes builds an error which is "Type sqlConnection is not defined". Can someone explain to me why this happen? I already imported the namespaces
View 2 Replies
View Related
Mar 25, 2008
Hello All!
I Wrote this code to connect to a mssql server 2005 express db in visual basic 2008 express edition.
Public Function SelectRows(ByVal dataSet As DataSet, ByVal connectionString As String, ByVal queryString As String) As DataSet
Using connection As New SqlConnection(connectionString)
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = New SqlCommand(queryString, connection)
adapter.Fill(dataSet)
Return dataSet
End Using
End Function
Problem is that i allways get the Error msg Type SqlConnection is not defined.
Im totally new to VS Programming. Anyone can help me out?
Thanks alot.
View 4 Replies
View Related
Mar 10, 2008
I'm a noob to sql ce 3.5 and am getting the error "Type SqlConnection is not defined". I'm thinking this has something to do with the sql client not being installed but am not sure. I've tried adding - 'Imports System.Data.SqlClient' but it's not available, anyone ahave any ideas on how to fix this?
Thanks,
View 4 Replies
View Related
Feb 14, 2008
Hi all,
In the VB 2005 Express, I can get the SqlConnection and ConnectionString of a Database "shcDB" in the Object Explorer of SQL Server Management Studio Express (SSMSE) by the following set of code:
///--CallshcSpAdoNetVB2005.vb--////
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Public Class Form1
Public Sub InsertNewFriend()
Dim connectionString As String = "Data Source=.SQLEXPRESS;Initial Catalog=shcDB;Integrated Security=SSPI;"
Dim connection As SqlConnection = New SqlConnection(connectionString)
Try
connection.Open()
Dim command As SqlCommand = New SqlCommand("sp_insertNewRecord", connection)
command.CommandType = CommandType.StoredProcedure
.......................................
etc.
///////////////////////////////////////////////////////
If the Database "shcDB" and the Stored Procedure "sp_inertNewRecord" are in the Database Explorer of VB 2005 Express, I plan to use "Data Source=local" in the following code statements to get the SqlConnection and ConnectionString:
.........................
........................
Dim connectionString As String = "Data Source=local;Initial Catalog=shcDB;Integrated Security=SSPI;"
Dim connection As SqlConnection = New SqlConnection(connectionString)
Try
connection.Open()
Dim command As SqlCommand = New SqlCommand("sp_insertNewRecord", connection)
command.CommandType = CommandType.StoredProcedure
........................
etc.
Is the "Data Source=local" statement right for this case? If not, what is the right code statement for my case?
Please help and advise.
Thanks,
Scott Chang
View 6 Replies
View Related
Apr 17, 2008
I defined the following connection string (strConn) and coded "Dim oConn As New SqlConnection(strConn)".In this VS 2005/ASP.net 2.0 program, 'SqlConnection' was underlined and showed 'Type SqlConnection is not defined' error.
What wrong with my VS 2005/ASPnet 2.0 coding, or SQL Server 2000 database configuration?
TIA,Jeffrey
connectionString="Data Source=webserver;Initial Catalog=Ssss;Persist Security Info=True;User ID=WWW;Password=wwwwwwww"providerName="System.Data.SqlClient"
View 3 Replies
View Related
Sep 23, 2006
Dear all, I'm using sqldatareader to return data that i need and then bind it to the gridview. Anyway, I'm facing the above error message. Please help, thanks. Levine
View 5 Replies
View Related
May 21, 2008
I am trying to bind the data to a list box....i am using a stored procedure instead of a select query. Unfortunately the error is throwing up. Correct me where iam going wrong. Is my syntax correct
SqlConnection cn = new SqlConnection("User id=******;password=******;database=sampleecsphase2test;Data source=primasqltst\qa");
cn.Open();SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;SqlDataReader dr = new SqlDataReader();
dr = cmd.ExecuteReader();
listBox1.DataSource = dr;
View 8 Replies
View Related
Dec 13, 2007
My web project (ASP.NET 2.0 / C#) runs against sql server 2000 and uses the System.Data.SqlClient.using System.Data.SqlClient;
I use System.Data.SqlClient.SqlConnection and System.Data.SqlClient.SqlCommand to make the connections to the database and do selects and updates. Is it correct to continue to use these against SQL Server 2005? I ask because I made a connection string (outside of .Net) for SqlServer 2005 using the SQL native provider and it had the following - Provider=SQLNCLI.1 and any connection strings I had made (also outside of ASP.NET) fro SQL Server all used Provider=SQLOLEDB.1. This is why I wondered if there is a different SqlClient in .Net 2.0 for SQL Server 2005?
Cheers
Al
View 1 Replies
View Related
Jan 17, 2008
Hi all,
In my SQL Server Management Studio Express (SSMSE), I executed the following sql code suuccessfully:
--insertNewRocord.sql--
USE shcDB
GO
CREATE PROC sp_insertNewRecord @procPersonID int,
@procFirstName nvarchar(20),
@procLastName nvarchar(20),
@procAddress nvarchar(50),
@procCity nvarchar(20),
@procState nvarchar(20),
@procZipCode nvarchar(20),
@procEmail nvarchar(50)
AS INSERT INTO MyFriends
VALUES (@procPersonID, @procFirstName, @procLastName, @procAddress,
@procCity, @procState, @procZipCode, @procEmail)
GO
EXEC sp_insertNewRecord 7, 'Peter', 'Wang', '678 Old St', 'Detroit',
'Michigon', '67899', 'PeterWang@yahoo.com'
GO
=======================================================================
Now, I want to insert a new record into the dbo.Friends table of my shcDB by executing the following T-SQL and Visual Basic 2005 codes that are programmed in a VB2005 Express project "CallshcDBspWithAdoNet":
--Form1.vb--
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Public Class Form1
Public Sub InsertNewFriend()
Dim connectionString As String = "Integrated Security-SSPI;Persist Security Info=False;" + _
"Initial Catalog=shcDB;Data Source=.SQLEXPRESS"
Dim connection As SqlConnection = New SqlConnection(connectionString)
connection.Open()
Try
Dim command As SqlCommand = New SqlCommand("sp_InsertNewRecord", connection)
command.CommandType = CommandType.StoredProcedure
EXEC sp_insertNewRecord 6, 'Craig', 'Utley', '5577 Baltimore Ave',
'Ellicott City', 'MD', '21045', 'CraigUtley@yahoo.com'
Console.WriteLine("Row inserted: " + _
command.ExecuteNonQuery().ToString)
Catch ex As Exception
Console.WriteLine(ex.Message)
Throw
Finally
connection.Close()
End Try
End Sub
End Class
===========================================================
I ran the above project in VB 2005 Express and I got the following 5 errors:
1. Name 'EXEC' is not declared (in Line 16 of Form1.vb)
2. Method arguments must be enclosed in parentheses (in Line 16 of Form1.vb)
3. Name 'sd-insertNewRecord' is not declared. (in Line 16 of Form1.vb)
4.Comma, ')', or a valid expression continuation expected (in Line 16 of Form1.vb)
5. Expression expected (in Line 16 of Form1.vb)
============================================================
I know that "EXEC sp_insertNewRecord 6, 'Craig', 'Utley', '5577 Baltimore Ave',
'Ellicott City', 'MD', '21045', 'CraigUtley@yahoo.com' "in Line 16 of Form1.vb is grossly in error.
But I am new in doing the programming of T-SQL in VB 2005 Express and I am not able to change it.
Please help and advise me how to correct these problems.
Thanks in advance,
Scott Chang
View 22 Replies
View Related
Jan 23, 2008
Hi Jonathan Kehayias, Thanks for your valuable response.
I had a hard time to sumbit my reply in that original thread yesterday. So I created this new thread.
Here is my response to the last code/instruction you gave me:
I corrected a small mistake (on Integrated Security-SSPI and executed the last code you gave me.
I got the following debug error message:
1) A Box appeared and said: String or binary data would be truncated.
The statement has been terminated.
|OK|
2) After I clicked on the |OK| button, the following message appeared:
This "SqlException was unhandled
String or binary data would be truncated.
The statement has been terminated."
is pointing to the "Throw" code statement in the middle of
.......................................
Catch ex As Exception
MessageBox.Show(ex.Message)
Throw
Finally
..........
Please help and advise how to correct this problem in my project that is executed in my VB 2005 Express-SQL Server Management Studio Express PC.
Thanks,
Scott Chang
The code of my Form1.vb is listed below:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Public Class Form1
Public Sub InsertNewFriend()
Dim connectionString As String = "Data Source=.SQLEXPRESS;Initial Catalog=shcDB;Integrated Security=SSPI;"
Dim connection As SqlConnection = New SqlConnection(connectionString)
Try
connection.Open()
Dim command As SqlCommand = New SqlCommand("sp_insertNewRecord", connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.Add("@procPersonID", SqlDbType.Int).Value = 7
command.Parameters.Add("@procFirstName", SqlDbType.NVarChar).Value = "Craig"
command.Parameters.Add("@procLastName", SqlDbType.NVarChar).Value = "Utley"
command.Parameters.Add("@procAddress", SqlDbType.NVarChar).Value = "5577 Baltimore Ave"
command.Parameters.Add("@procCity", SqlDbType.NVarChar).Value = "Ellicott City"
command.Parameters.Add("@procState", SqlDbType.NVarChar).Value = "MD"
command.Parameters.Add("@procZipCode", SqlDbType.NVarChar).Value = "21045"
command.Parameters.Add("@procEmail", SqlDbType.NVarChar).Value = "CraigUtley@yahoo.com"
Dim resulting As String = command.ExecuteNonQuery
MessageBox.Show("Row inserted: " + resulting)
Catch ex As Exception
MessageBox.Show(ex.Message)
Throw
Finally
connection.Close()
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InsertNewFriend()
End Sub
End Class
View 6 Replies
View Related
Apr 12, 2006
What different are there between connectionString (Part 1) and connectionString (Part 2) in web.config
The CCWW is my PC's name, normally I can connect to the database ASPNETDB.MDF correctly either Part 1 or Part 2 in a web page,After I open Database Explorer panel and browse ASPNETDB.MDF, I can't connect to database using Part 2 when I open a webpage in Microsoft Visual Web Developer 2005 Express Edition,but I can correctly open a webpage using Part 1 after I open Database Explorer panel.
What different are there between connectionString (Part 1) and connectionString (Part 2) in web.config?
I guess while I use Part 1 to connect, maybe it will be cancel exclusive method of the database ASPNETDB.MDF first, but when I connect to database using Part 2, maybe two programms both Part 2 and Database Explorer visit ASPNETDB.MDF at the same time!
--------------------------------------Part 1------------------------------------------------------------------------<add name="MyConnect" connectionString="Data Source=.SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|ASPNETDB.MDF" providerName="System.Data.SqlClient" /> --------------------------------------Part 1------------------------------------------------------------------------
--------------------------------------Part 2------------------------------------------------------------------------<add name="MyConnect" connectionString="Data Source=CCWWSQLEXPRESS;Initial Catalog=ASPNETDB.MDF;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|ASPNETDB.MDF" providerName="System.Data.SqlClient" />--------------------------------------Part 2------------------------------------------------------------------------
View 2 Replies
View Related
Apr 2, 2008
hai,
how can i identify the function is user defined or the system defined function....................
View 1 Replies
View Related
May 14, 2008
2 examples:
1) Rows ordered using textual id rather than numeric id
Code Snippet
select
cast(v.id as nvarchar(2)) id
from
(
select 1 id
union select 2 id
union select 11 id
) v
order by
v.id
Result set is ordered as: 1, 11, 2
I expect: 1,2,11
if renamed or removed alias for "cast(v.id as nvarchar(2))" expression then all works fine.
2) SQL server reject query below with next message
Server: Msg 169, Level 15, State 3, Line 16
A column has been specified more than once in the order by list. Columns in the order by list must be unique.
Code Snippet
select
cast(v.id as nvarchar(2)) id
from
(
select 1 id
union select 2 id
union select 11 id
) v
cross join (
select 1 id
union select 2 id
union select 11 id
) u
order by
v.id
,u.id
Again, if renamed or removed alias for "cast(v.id as nvarchar(2))" expression then all works fine.
It reproducible on
Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) May 3 2005 23:18:38 Copyright (c) 1988-2003 Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)
and
Microsoft SQL Server 2005 - 9.00.3042.00 (Intel X86) Feb 9 2007 22:47:07 Copyright (c) 1988-2005 Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)
In both cases database collation is SQL_Latin1_General_CP1251_CS_AS
If I check quieries above on database with SQL_Latin1_General_CP1_CI_AS collation then it works fine again.
Could someone clarify - is it bug or expected behaviour?
View 12 Replies
View Related
Oct 4, 2006
Hi , I have a database that records the users entrance to a building.The dates are recorded also .I have written some codes that to detect the period of dates that the person has entered.Lets say that a person named as jhon has entered the building on the days 02/08/2006 and 05/08/2006 and 11/08/2006 .Those dates are formated as dd/mm/yyyy . So that john has entered building for 3 times and the periods for the dates are one after another entrance is 3 days + 6 days =9 days .If you divide 9 by 3 we get the arithmetic average number 3 .So that we can say as john visits this building every 3 days and we can guess the next day that he may come. I have coded this and works great .I will paste the codes to the end of my message.But a master programmer friend of mine has said that I should have get this result by without writing code , by just using sql database .But some kind of stored procedure I mustn't use.So that I thought it can be done by views in sqldb .By using sql server enterprise manager I tried to use views but I could not succees. Can anyone guess this ? Here are my vb codes ... database data types : entry_id : int , identity user_id : int movie : nvarchar (50) dateenter : datetime stored procedure that selects the data from db: CREATE PROCEDURE veri_al ( @user_id int ) AS SELECT entry_id ,user_id, movie, dateenter from uye_aktiviteleri where (user_id=@user_id) ORDER BY entry_id ASC GO Code:Dim conn As New SqlClient.SqlConnection conn.ConnectionString = "data source=localhost;initial catalog=AFM;uid=nusret;pwd=araz" Dim command As New SqlClient.SqlCommand command.CommandText = "[veri_al]" command.CommandType = CommandType.StoredProcedure command.Connection = conn command.Parameters.Add("@user_id", SqlDbType.Int, 4).Value = Val(TextBox1.Text) If Not IsNumeric(TextBox1.Text) Then Exit Sub End If Try Dim adapter As New SqlClient.SqlDataAdapter adapter.SelectCommand = command Dim ds As New DataSet adapter.Fill(ds, "uyeler") DataGrid1.DataSource = ds.Tables("uyeler") Dim recordcount As Integer 'Found the recordcount recordcount = ds.Tables("uyeler").Rows.Count Dim mydatarow_ilk As DataRow Dim mydatarow_son As DataRow 'in stored procedure I used ORDER BY entry_id ASC so that first datarow 'will always be the first visit date and the last record of the 'datarow will be the last visit date mydatarow_first= ds.Tables("uyeler").Rows(0) mydatarow_last = ds.Tables("uyeler").Rows(recordcount - 1) Dim first_date As String Dim last_date As String first_date = mydatarow_first("dateenter") last_date =mydatarow_last("dateenter") Dim average_ As Integer 'What is the aveare of the visits ortalama = DateDiff("d", first_date , last_date ) / recordcount Label2.Text = "Member had visited for " & recordcount & "times" Label3.Text = "by average he/she comes here " & ortalama & " day to another." Dim last_time_visit As Integer last_time_visit = DateDiff("d", last-date , DateTime.Today()) Label4.Text = "Until the last visit it had been" & last_time_visit & " days" Label5.Text = "Guess for the next visit is" & DateAdd("d", average_ , last_date) ' MsgBox("average visits" & ortalama & " days" ) Catch z As Exception MsgBox("error : " & z.Message()) Finally MsgBox("Successfully calculated") End Try End Sub
View 1 Replies
View Related
Jul 20, 2005
Hi,I have a table of Locations around the country. My system produces reportsbased on these Locations. I also have a table containing Brick Codes e.g.Brick Post CodeAB51 AB51AB52 AB52AB55 AB55AB56 AB56AL01 AL1AL02 AL2AL03 AL3AL04 AL4How can I compare the first 3 or 4 letters of the postcode in the Locationstable to the corresponding entry in the Brick Codes table so I can add it tomy report?Thanks for your help
View 2 Replies
View Related
Oct 10, 2006
Hi,
I have another question about ADO (using C++). I have searched the MSDN but I haven't found a answer to my question (maybe I'm just too stupid)... If I make a connection to my SQL Server there may occur some errors, but how to find out what went wrong ?
In terms of code I have e.g. something like that:
try { connection->Open(ConnectionString,Username,Password,ADODB::adConnectUnspecified);
...} catch (_com_error& e) { long numErrors = connection->Errors->Count; for (long i=0; i<numErrors; i++) { ADODB::ErrorPtr pErr = connection->Errors->GetItem(i); ..... }}
Now I could get the error number by pErr->GetNumber().
But with which symbolic constant has this to be compared to find out which error occured ?? I didn't find any...Or is there another better way to do this ?
P.S. I am using SQL Server 2005 Express
View 7 Replies
View Related
Jan 8, 2008
How can I test sql codes and don't want to connect to company database?
My company is using sql server 2000.
Below is the test codes which create a simple table, calculate and just want to check before
writing more complicated codes.
Thanks
Daniel Ku
-------------------------------------------------------------------------------------------------------------------------------
create table EquipmentUptime (
equipmentId int not null
,transactionId int not null
,dateOccured datetime not null
)
go
--
insert into EquipmentUptime values (1,200,'01/01/2007')
insert into EquipmentUptime values (2,200,'01/01/2007')
insert into EquipmentUptime values (3,200,'01/01/2007')
insert into EquipmentUptime values (2,100,'02/12/2007')
insert into EquipmentUptime values (1,100,'02/25/2007')
insert into EquipmentUptime values (3,100,'03/10/2007')
insert into EquipmentUptime values (1,200,'03/14/2007')
go
--
select
equipmentId
,100*(cast((cast(sum(UpDays)as decimal(6,3))/cast(365 as decimal(6,3))) as decimal(4,3))) 'PctUpTime'
from
(
select
c.equipmentId
,datediff(dd,c.[UpDate],c.DownDate) 'UpDays'
from
(
select
a.equipmentId
,a.dateOccured as 'UpDate'
,coalesce(
(select top 1
b.dateOccured
from
EquipmentUptime b
where
transactionId=100
and b.equipmentId=a.equipmentId
and b.dateOccured >= a.dateOccured
order by
b.dateOccured asc
),'01/01/2008') as 'DownDate'
from
EquipmentUptime a
where
a.transactionId=200
) c
) d
group by
d.equipmentId
View 1 Replies
View Related
Jun 28, 2007
My data flow component is throwing an error and the only help I get is the following:
error code: -1071607694
error column: 257
What in the world does this mean? Can it get more cryptic than this?
View 1 Replies
View Related
Jul 29, 2001
Hi,
I have a table with a primary key, what I really need is something like an IDENTITY, but with the character 'X' and the last to digits of the year added on the front. Is there another way to update the field automatically like an IDENTITY would do, automatically incrementing as fields are inserted.
View 1 Replies
View Related
Mar 2, 1999
I apologize for the length of this message, but I think I need to include all this info so that the problem is understood. I am having what appears to be a problem capturing the return code from a failed BCP.
I create a stored proc to use BCP to load a table:
create procedure sp_bcp_load as
declare @RC int
execute @RC = master..xp_cmdshell "bcp JON..W4KPV in e:inetpubftprootfinreslaw4kpv.g4000.data /Sdbmtss1 /m 0 /f d:mssqluserdatafinresW4KPV.fmt /Usa /P /e d:mssqluserdatafinrescp1.err /t""|"" /r "
select 'Return code from bcp = ', @RC
if @RC <> 0
BEGIN
print 'BCP Error.'
return (8)
END
GO
If I execute the SP, and encounter a transaction log full error, the return code is still zero:
1000 rows sent to SQL Server. 45000 total
1000 rows sent to SQL Server. 46000 total
Msg 1105, Level 17, State 2:
Server 'DBMTSS1', Line 1:
Can't allocate space for object 'Syslogs' in database 'Jon' because
the 'logsegment' segment is full. If you ran out of space in Syslogs,
dump the transaction log. Otherwise, use ALTER DATABASE or sp_extendsegment to increase the size of the segment.
(54 row(s) affected)
----------------------- -----------
Return code from bcp = 0
If I execute the SP again, it correctly returns a non-zero value:
Msg 1105, Level 17, State 2:
Server 'DBMTSS1', Line 1:
Can't allocate space for object 'Syslogs' in database 'Jon' because
the 'logsegment' segment is full. If you ran out of space in Syslogs, dump the transaction log. Otherwise, use ALTER DATABASE or sp_extendsegment to increase the size of the segment.
(6 row(s) affected)
----------------------- -----------
Return code from bcp = 1
(1 row(s) affected)
BCP Error.
Does anybody have an idea why this behaves this way? Any suggestions on how to trap an error on the first call?
Thanks,
Jon Carter
View 2 Replies
View Related
Jul 6, 2004
hey all
i am stuck with this little problem
I have a table with people's names and addresses and i have one column for the zip codes. sometimes it includes 5 digit zip codes like '70820' and some times it includes all nine digits like '70820-4565'
is there anyway to move the last 4 digits of the long zip codes into a new column? and remove the dash?
thanks
View 6 Replies
View Related
Aug 28, 2007
Aloha !
I am posting this information simply as an FYI. This is in reference to the MS-SQL command "CONVERT"
I spent over 2 hours :rolleyes: screwing around trying to find out different ways of formatting dates from MS-SQL into something that makes sense for what I needed. I googled everything I could think of and found multiple references that said the info is available on MSDN.. but I could not find it. What I did find were thousands of relatively useless references to "format codes" for converting dates, but with no references to what the different format codes would ultimately yield, or what format codes were available to use.
What I ended up doing was writing a small script to generate a list of all of the variations I could find.
Below is the script, and the output that it yielded.
Now, before I get bombarded with "there is a better way" I know there probably is. But this is the way that I needed to do it this particular time. If there are technical errors in my explanation, anyone is welcome to correct them. But after 2 hours of messing with this for what should have been a super simple single .0009 second command, I am just irritated beyond belief that it had to be this complicated to find any useful information on the subject. That is why I am creating this. Hopefully it helps someone else.
The format for the MS SQL CONVERT command is :
CONVERT( length_of_output, date, format_code )
length_of_output : is exactly that . the number of characters that you want returned as your result. If you use a length of 6 you will only see the first 6 characters that are returned. I found the longest valid length to be 28 characters, but I went as high as 128 just for giggles and to see if it revealed any secrets.
date : is a valid date, I used directly the getdate() function
format_code : well.. that's the tricky part. See below.
What I did was ran a script that originally went from 1 to 20,000. It crashed at 15. Apparently the format codes are not totally sequential. So I put in an on error resume next.
What I found is that :
1) the codes are not uninterrupted sequential numbers.
2) the code output repeats every 255
3) negative numbers can be used, but its pointless.
4) useful valid codes are in the ranges of : 0-14, 20-25, 100-114, 120, 121, 126, 130 and 131
5) 0-25 typically represent "short dates" with the year being only 2 digits, but there are exceptions
6) 100 and above always returned a 4 digit year. the exception was 130 and 131, I don't know what it was trying to do.
Here is the script i ran
<%
on error resume next
for iintCounter = 0 to 256
SQL = "SELECT CONVERT(CHAR(128), getdate(), " & iintCounter & " ) as TheDate"
Set rsTheDateFormat = TheDatabase.Execute(SQL)
response.write SQL & " = " & rsTheDateFormat("TheDate") & "<br>"
set rsTheDateFormat = nothing
next
%>
and here is the output
SELECT CONVERT(CHAR(128), getdate(), 0 ) as TheDate = Aug 28 2007 6:46AM
SELECT CONVERT(CHAR(128), getdate(), 1 ) as TheDate = 08/28/07
SELECT CONVERT(CHAR(128), getdate(), 2 ) as TheDate = 07.08.28
SELECT CONVERT(CHAR(128), getdate(), 3 ) as TheDate = 28/08/07
SELECT CONVERT(CHAR(128), getdate(), 4 ) as TheDate = 28.08.07
SELECT CONVERT(CHAR(128), getdate(), 5 ) as TheDate = 28-08-07
SELECT CONVERT(CHAR(128), getdate(), 6 ) as TheDate = 28 Aug 07
SELECT CONVERT(CHAR(128), getdate(), 7 ) as TheDate = Aug 28, 07
SELECT CONVERT(CHAR(128), getdate(), 8 ) as TheDate = 06:46:45
SELECT CONVERT(CHAR(128), getdate(), 9 ) as TheDate = Aug 28 2007 6:46:45:507AM
SELECT CONVERT(CHAR(128), getdate(), 10 ) as TheDate = 08-28-07
SELECT CONVERT(CHAR(128), getdate(), 11 ) as TheDate = 07/08/28
SELECT CONVERT(CHAR(128), getdate(), 12 ) as TheDate = 070828
SELECT CONVERT(CHAR(128), getdate(), 13 ) as TheDate = 28 Aug 2007 06:46:45:507
SELECT CONVERT(CHAR(128), getdate(), 14 ) as TheDate = 06:46:45:507
SELECT CONVERT(CHAR(128), getdate(), 20 ) as TheDate = 2007-08-28 06:46:45
SELECT CONVERT(CHAR(128), getdate(), 21 ) as TheDate = 2007-08-28 06:46:45.540
SELECT CONVERT(CHAR(128), getdate(), 22 ) as TheDate = 08/28/07 6:46:45 AM
SELECT CONVERT(CHAR(128), getdate(), 23 ) as TheDate = 2007-08-28
SELECT CONVERT(CHAR(128), getdate(), 24 ) as TheDate = 06:46:45
SELECT CONVERT(CHAR(128), getdate(), 25 ) as TheDate = 2007-08-28 06:46:45.540
SELECT CONVERT(CHAR(128), getdate(), 100 ) as TheDate = Aug 28 2007 6:46AM
SELECT CONVERT(CHAR(128), getdate(), 101 ) as TheDate = 08/28/2007
SELECT CONVERT(CHAR(128), getdate(), 102 ) as TheDate = 2007.08.28
SELECT CONVERT(CHAR(128), getdate(), 103 ) as TheDate = 28/08/2007
SELECT CONVERT(CHAR(128), getdate(), 104 ) as TheDate = 28.08.2007
SELECT CONVERT(CHAR(128), getdate(), 105 ) as TheDate = 28-08-2007
SELECT CONVERT(CHAR(128), getdate(), 106 ) as TheDate = 28 Aug 2007
SELECT CONVERT(CHAR(128), getdate(), 107 ) as TheDate = Aug 28, 2007
SELECT CONVERT(CHAR(128), getdate(), 108 ) as TheDate = 06:46:45
SELECT CONVERT(CHAR(128), getdate(), 109 ) as TheDate = Aug 28 2007 6:46:45:913AM
SELECT CONVERT(CHAR(128), getdate(), 110 ) as TheDate = 08-28-2007
SELECT CONVERT(CHAR(128), getdate(), 111 ) as TheDate = 2007/08/28
SELECT CONVERT(CHAR(128), getdate(), 112 ) as TheDate = 20070828
SELECT CONVERT(CHAR(128), getdate(), 113 ) as TheDate = 28 Aug 2007 06:46:45:930
SELECT CONVERT(CHAR(128), getdate(), 114 ) as TheDate = 06:46:45:930
SELECT CONVERT(CHAR(128), getdate(), 120 ) as TheDate = 2007-08-28 06:46:45
SELECT CONVERT(CHAR(128), getdate(), 121 ) as TheDate = 2007-08-28 06:46:45.943
SELECT CONVERT(CHAR(128), getdate(), 126 ) as TheDate = 2007-08-28T06:46:45.990
SELECT CONVERT(CHAR(128), getdate(), 130 ) as TheDate = 15 ????? 1428 6:46:46:040AM
SELECT CONVERT(CHAR(128), getdate(), 131 ) as TheDate = 15/08/1428 6:46:46:040AM
SELECT CONVERT(CHAR(128), getdate(), 256 ) as TheDate = Aug 28 2007 6:46AM
View 11 Replies
View Related
Jan 29, 2004
I have files with area codes that are several years old. Everything I've seen about updating area codes deals with area codes that are current and are about to split in the near future. How would I go about bringing old area codes up to date?
View 8 Replies
View Related
May 2, 2007
I am working with a table that has zip codes listed in lengths of 9,8,5 and 4 digits. The table is created this way and I have no way of changing the data outside of SQL. I am trying to get the last four digits off of all the zip codes so that I only have to work with zip codes in lengths of 5 and 4
Thanks,
Pizzo36
View 5 Replies
View Related
Nov 30, 2007
I hope you can help me out here. I don't know if I even have enough information to give you. I need to create a SQL that pulls the most commonly Billed CPT Codes. The Fields that I am going to use is the CPTCODES Field and the DOS FROM Field. How I was going to right my statement is below. Do I need to have a count or anything?
SELECT TOP 100 DOSFROM, DOSThru, CPTCODES
FROM VW_1000_Commonly_Billed_Charges
WHERE (DOSFROM >= @BottomDate) AND (DOSThru <= @TopDate)
View 3 Replies
View Related
Jul 23, 2005
HiIs there any way to store gitar codes in sql server table. or want toset specific "COLLATE".ThanksDishan
View 7 Replies
View Related
Jul 23, 2005
I'm looking to find out how I'd go about setting up a database where avisitor to my site could punch in their postal code, and find out how farthey are from another postal code. For example, AutoTrader has this featureI believe to tell you how far the vehicle is from you. Dating sites havethem so you can do proximity searches.Anyone have any ideas where I could start? I'm thinking the post office,but if anyone else has suggestions, I'm open to hear them.Thanks!
View 4 Replies
View Related
May 11, 2006
Using the following syntax, sometimes non-zero error codes are returned:
D:SQL Server x86Servers>start /wait setup
D:SQL Server x86Servers>echo %errorlevel%
3010
Searching BOL for 3010 returns nothing.
Other error codes that were seen are 1603 and 9009.
What do these error codes mean? Is there a place where they can be looked up?
View 4 Replies
View Related
Aug 10, 2007
I need to create formatting that is a bit different from the standard formatting codes in SSRS. Specifically, I need to have the percent sign come right after the number (SSRS inserts a space), whereas with currency fields I need to inster a space between the $ and the number (SSRS has no space). Is there any way to do this with custom formatting codes, or will I need to go through and add the percent and dollar sign in manually to each field so that the space can either be removed or inserted?
View 15 Replies
View Related