Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Friday, March 30, 2012

having trouble connecting to database

Hi I am new at this.

I have a little program written in C# in asp.net. The program basically accesses a database and stores new records. The database is supposedly already attached to MSDE so I am able to see the tables of the database inside asp.net. I can click on the individual slots of the table and modify the datas manually. However, I want to connect to the database from my C# program and be able to input data into the database via the website that the C# program produces. After I type in the data into the website and click the submit button on the website, I get an error page that says this:

Login failed for user 'sa'

the line of code thats causing this error is:

con =

new SqlConnection("data source=(local)\\NetSdk; initial catalog=Friends; user id=sa");

Why is it not able to connect to the database?

YourChild:


con =

new SqlConnection("data source=(local)\\NetSdk; initial catalog=Friends; user id=sa");



I am taking the liberty to presume that your database name is Friends.I just couldn't figure what the "\\NetSdk" means. Perhaps you can addsomething to my knowledge.

Most probably if you aren't using Integrated Security for accessing thedatabase, you'd need to specify the password in the connection stringas well. You can make it something like this:

con =new SqlConnection("data source=(local);initial catalog=Friends;user id=sa;pwd="yourpassword")
Remember,it is a bad habit to store your connection string in the code. Tryputting it in the web.config, but you might want to do this later, whenyou get the hang of things.

Smiles.|||

uXuf:

YourChild:


con =

new SqlConnection("data source=(local)\\NetSdk; initial catalog=Friends; user id=sa");



I am taking the liberty to presume that your database name is Friends. I just couldn't figure what the "\\NetSdk" means. Perhaps you can add something to my knowledge.

Most probably if you aren't using Integrated Security for accessing the database, you'd need to specify the password in the connection string as well. You can make it something like this:

con =new SqlConnection("data source=(local);initial catalog=Friends;user id=sa;pwd="yourpassword")

Remember, it is a bad habit to store your connection string in the code. Try putting it in the web.config, but you might want to do this later, when you get the hang of things.

Smiles.

Thank you it works! I'm so glad you came by! now I am in the process of trying to stick the 'userName' and 'password' into the web.config file by using:

<

identityimpersonate="true"userName="sa"password="mypassword"/>

only now when I hit compile, Windows is giving me an error that says:

"Unable to start debugging on the web server. Server side-error occurred on sending debug HTTP request." Do I need to change something else to make this work?

There is another piece of code at the top of the web.config file that looks like this:

<authenticationmode="None"/>

Should "None" be set to "Windows"?

Then there is another username and password inside the "Directory Security" in IIS via 'property' for the virtual directory corresponding to the directory of the project. Is this username and password associated with the userName and password used to access the database?

Having problems with SQLXML bulk import using diffgram

I have a program that writes out xml files that I use to import into SQL
server. When I start importing, most of the files that I have successfully
import, but some of them error out with the message: "SQLOLEDB Error
Description: Empty update, no updatable rows found Transaction aborted".
I've looked at the xml diffgram and there are definitely modified and
inserted rows in it. Has anyone run across this? I'd be glad to post the
diffgram here if anyone would like to see it.
Thanks,
Rob Baber
Do you use the diffgram or updategram format?
Sending a repro would help.
Thanks
Michael
"Rob Baber" <Rob Baber@.discussions.microsoft.com> wrote in message
news:E10640A7-BCE5-42AE-B842-C9956E067812@.microsoft.com...
>I have a program that writes out xml files that I use to import into SQL
> server. When I start importing, most of the files that I have
> successfully
> import, but some of them error out with the message: "SQLOLEDB Error
> Description: Empty update, no updatable rows found Transaction aborted".
> I've looked at the xml diffgram and there are definitely modified and
> inserted rows in it. Has anyone run across this? I'd be glad to post the
> diffgram here if anyone would like to see it.
> Thanks,
> Rob Baber
|||Could you please check the generated T-SQL by the SqlXml by using the
profiler? You are most likely using a diffgram behaving different than your
expectation or hitting a bug in SqlXml.
If you check out the sql and it seems like a wrongly generated one, could
you please post your diffgram and t-sql so that we can investigate if it is
a bug.
Thanks
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Rob Baber" <Rob Baber@.discussions.microsoft.com> wrote in message
news:E10640A7-BCE5-42AE-B842-C9956E067812@.microsoft.com...
>I have a program that writes out xml files that I use to import into SQL
> server. When I start importing, most of the files that I have
> successfully
> import, but some of them error out with the message: "SQLOLEDB Error
> Description: Empty update, no updatable rows found Transaction aborted".
> I've looked at the xml diffgram and there are definitely modified and
> inserted rows in it. Has anyone run across this? I'd be glad to post the
> diffgram here if anyone would like to see it.
> Thanks,
> Rob Baber
sql

Having problems with SQLXML bulk import using diffgram

I have a program that writes out xml files that I use to import into SQL
server. When I start importing, most of the files that I have successfully
import, but some of them error out with the message: "SQLOLEDB Error
Description: Empty update, no updatable rows found Transaction aborted".
I've looked at the xml diffgram and there are definitely modified and
inserted rows in it. Has anyone run across this? I'd be glad to post the
diffgram here if anyone would like to see it.
Thanks,
Rob BaberDo you use the diffgram or updategram format?
Sending a repro would help.
Thanks
Michael
"Rob Baber" <Rob Baber@.discussions.microsoft.com> wrote in message
news:E10640A7-BCE5-42AE-B842-C9956E067812@.microsoft.com...
>I have a program that writes out xml files that I use to import into SQL
> server. When I start importing, most of the files that I have
> successfully
> import, but some of them error out with the message: "SQLOLEDB Error
> Description: Empty update, no updatable rows found Transaction aborted".
> I've looked at the xml diffgram and there are definitely modified and
> inserted rows in it. Has anyone run across this? I'd be glad to post the
> diffgram here if anyone would like to see it.
> Thanks,
> Rob Baber|||Could you please check the generated T-SQL by the SqlXml by using the
profiler? You are most likely using a diffgram behaving different than your
expectation or hitting a bug in SqlXml.
If you check out the sql and it seems like a wrongly generated one, could
you please post your diffgram and t-sql so that we can investigate if it is
a bug.
Thanks
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"Rob Baber" <Rob Baber@.discussions.microsoft.com> wrote in message
news:E10640A7-BCE5-42AE-B842-C9956E067812@.microsoft.com...
>I have a program that writes out xml files that I use to import into SQL
> server. When I start importing, most of the files that I have
> successfully
> import, but some of them error out with the message: "SQLOLEDB Error
> Description: Empty update, no updatable rows found Transaction aborted".
> I've looked at the xml diffgram and there are definitely modified and
> inserted rows in it. Has anyone run across this? I'd be glad to post the
> diffgram here if anyone would like to see it.
> Thanks,
> Rob Baber

Wednesday, March 28, 2012

Having major problems with my insert query logic

I have a perl program that is looping through a hash of a hash. I need to Update any existing records but also insert any new records in the table using collected data in the hash.

Life would be very simple if it was possible to use a Where Clause in an Insert statement but not does not work.

Here is some example code from my program:
sub Test{
foreach my $table(keys %$HoH){
foreach my $field(keys %{$HoH->{$table}}){
if($table eq "CPU"){
my $CPUstatement = "INSERT INTO CPU(CPUNumber, Name, MaxClockSpeed, SystemNetName)
Values ('$field',
'$HoH->{CPU}{$field}{Name}',
'$HoH->{CPU}{$field}{MaxClockSpeed}' ,
'$HoH->{Host}{SystemNetName}')";
print "$CPUstatement\n";
if ($db->Sql($CPUstatement))
{
print "Error on SQL Statement\n";
Win32::ODBC::DumpError();
}
else
{
print "successful\n";
}
}
}


}
}

Thanks,
LauraI'm assuming that your hash values are printing as expected. The construction looks strange (but it could be fine) to me.

Is the CPUNumber the primary key for the CPU table? If so, you could use something like:my $CPUstatement = "IF EXISTS (SELECT * FROM CPU WHERE CPUNUMBER = '$field')
THEN UPDATE CPU
SET Name = '$HoH->{CPU}{$field}{Name}'
, MaxClockSpeed = '$HoH->{CPU}{$field}{MaxClockSpeed}'
, SystemNetName = '$HoH->{Host}{SystemNetName}'
WHERE CPUNumber = '$field'
ELSE INSERT INTO CPU(CPUNumber, Name, MaxClockSpeed, SystemNetName)
Values (
'$field'
, '$HoH->{CPU}{$field}{Name}'
, '$HoH->{CPU}{$field}{MaxClockSpeed}'
, '$HoH->{Host}{SystemNetName}')";-PatP|||I tried your code and I am getting an error -> Incorrect Systax near the keyword 'THEN'

What do you suppose that means? I copied and pasted the code as is.

Thanks,
Laura|||That error means that I don't proofread very well ;) I was composing as I typed, and simply got ahead of myself then didn't clean up afterwards. Just remove the word THEN from that statement. Sorry.

-PatP|||oh wow. That's so cool, it worked.

Thanks Pat for your help. I learn new things everyday.

-Laura|||I just love it when I can make a lovely lady happy!

-PatP

Friday, March 23, 2012

have a problem

Who knows how to fix this..
who knows how to fix this
> MMC cannot open the file C:\Program Files\Microsoft SQL
Server\80\Tools\BINN\Sql Server Enterprise Manager.MSC.
This may be because the file doesnt exist, is not an MMC console, or
was created by a later version of MMC. This may also be because
Thx
Vegita
---
Posted via http://www.mcse.ms
---
View this thread: http://www.mcse.ms/message412335.htmlHi Vegita.
The error indicates one of a few things is the problem - have you checked
each of them? Can you offer us anything more to work with, such as:
(a) Does the file actually exist?
(b) Have you upgraded MMC.exe? (added new service packs lately etc)
(c) Have you uninstalled the SQL client tools perhaps?
A simple catch-all approach to solving the problem might be to simply
re-install the SQL Server Client Tools (not the server) which will probably
get you out of jail..
Regards,
Greg Linwood
SQL Server MVP
"Vegita" <Vegita.11xyqq@.mail.mcse.ms> wrote in message
news:Vegita.11xyqq@.mail.mcse.ms...
> Who knows how to fix this..
> who knows how to fix this
> > MMC cannot open the file C:\Program Files\Microsoft SQL
> Server\80\Tools\BINN\Sql Server Enterprise Manager.MSC.
> This may be because the file doesnt exist, is not an MMC console, or
> was created by a later version of MMC. This may also be because
> Thx
>
> Vegita
> ---
> Posted via http://www.mcse.ms
> ---
> View this thread: http://www.mcse.ms/message412335.html
>

have a problem

Who knows how to fix this..
who knows how to fix this
> MMC cannot open the file C:\Program Files\Microsoft SQL
Server\80\Tools\BINN\Sql Server Enterprise Manager.MSC.
This may be because the file doesnt exist, is not an MMC console, or
was created by a later version of MMC. This may also be because
Thx
Vegita
---
Posted via http://www.mcse.ms
---
View this thread: http://www.mcse.ms/message412335.htmlHi Vegita.
The error indicates one of a few things is the problem - have you checked
each of them? Can you offer us anything more to work with, such as:
(a) Does the file actually exist?
(b) Have you upgraded MMC.exe? (added new service packs lately etc)
(c) Have you uninstalled the SQL client tools perhaps?
A simple catch-all approach to solving the problem might be to simply
re-install the SQL Server Client Tools (not the server) which will probably
get you out of jail..
Regards,
Greg Linwood
SQL Server MVP
"Vegita" <Vegita.11xyqq@.mail.mcse.ms> wrote in message
news:Vegita.11xyqq@.mail.mcse.ms...
> Who knows how to fix this..
> who knows how to fix this
> Server\80\Tools\BINN\Sql Server Enterprise Manager.MSC.
> This may be because the file doesnt exist, is not an MMC console, or
> was created by a later version of MMC. This may also be because
> Thx
>
> Vegita
> ---
> Posted via http://www.mcse.ms
> ---
> View this thread: http://www.mcse.ms/message412335.html
>

Wednesday, March 21, 2012

Has anyone tried "Using SQL Stored procedure in MS ACCESS"?

I am developing a program using ms access with an SQL 2000 back end. I am using an odbc connection to access my data. Using this connection, i can only access the tables and views of my database. I am planning to create "Stored procedure" in SQL and connect it to my MS Access program but have no idea how to do it.

Please help! Thanks in Advance!Might I suggest an Access newsgroup as its an Access specific problem? SQL Server SPs should just be called like a SQL statement is executed, ie "exec usp_foo" instead of "select * from foo".|||if you want to view stored procedure from Access I suggest you to not use a Access Project (file .adp) instead of the classic Access database (.mdb);
in this way in the Query tab of you Access Project you will see views and stored procedure of the Sql server and then you can manage these directly by Access.
bye

Has anyone tried "Using SQL Stored procedure in MS ACCESS"?

I am developing a program using ms access with an SQL 2000 back end. I am using an odbc connection to access my data. Using this connection, i can only access the tables and views of my database. I am planning to create "Stored procedure" in SQL and connect it to my MS Access program but have no idea how to do it.

Please help! Thanks in Advance!Might I suggest an Access newsgroup as its an Access specific problem? SQL Server SPs should just be called like a SQL statement is executed, ie "exec usp_foo" instead of "select * from foo".|||if you want to view stored procedure from Access I suggest you to not use a Access Project (file .adp) instead of the classic Access database (.mdb);
in this way in the Query tab of you Access Project you will see views and stored procedure of the Sql server and then you can manage these directly by Access.
bye

Wednesday, March 7, 2012

Hard Code Native Error code in program?

Using VB 6, sp6,
On sql server 2000 (sp4)
When I try to establish a connection to the database
from a VB 6 program using ADO, I get a similar message
if the UserID does not exist or if the UserID does exist
but does not have the permission to the database.
The NativeError number is different,
NativeError - 18456 The UserID does not exist
NativeError - 4060 The UserID exists, but does not have permission
to the database.
Can I hard code the NativeError number in my VB 6
program to determine exactly what happened,
(the UserID did not exist or the UserID does exist but
does not have the proper permission.)
I worry that the code number might change in a future
version of sql server.
I hate to do this but there is no other way to determine
exactly what happened.
Thanks in Advance,
Laurence Nuttall
Programmer Analyst III
UCLA - Division of Continuing EducationIt's unlikely that the error codes would change. Could happen, but more
probable that additional codes would be added for other (and new)
situations.
If you are concerned, you could use a config file, and put the codes in the
config file. Have the app read the config file at start up and hold the
error codes in global variables. (An xml file works good for that.)
Otherwise, set them up as constants.
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"Larry" <bliff@.Blifff.com> wrote in message
news:OlggCs6mGHA.2360@.TK2MSFTNGP04.phx.gbl...
> Using VB 6, sp6,
> On sql server 2000 (sp4)
> When I try to establish a connection to the database
> from a VB 6 program using ADO, I get a similar message
> if the UserID does not exist or if the UserID does exist
> but does not have the permission to the database.
> The NativeError number is different,
> NativeError - 18456 The UserID does not exist
> NativeError - 4060 The UserID exists, but does not have permission
> to the database.
> Can I hard code the NativeError number in my VB 6
> program to determine exactly what happened,
> (the UserID did not exist or the UserID does exist but
> does not have the proper permission.)
> I worry that the code number might change in a future
> version of sql server.
> I hate to do this but there is no other way to determine
> exactly what happened.
> Thanks in Advance,
> Laurence Nuttall
> Programmer Analyst III
> UCLA - Division of Continuing Education
>
>|||It's unlikely that the error codes would change. Could happen, but more
probable that additional codes would be added for other (and new)
situations.
If you are concerned, you could use a config file, and put the codes in the
config file. Have the app read the config file at start up and hold the
error codes in global variables. (An xml file works good for that.)
Otherwise, set them up as constants.
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"Larry" <bliff@.Blifff.com> wrote in message
news:OlggCs6mGHA.2360@.TK2MSFTNGP04.phx.gbl...
> Using VB 6, sp6,
> On sql server 2000 (sp4)
> When I try to establish a connection to the database
> from a VB 6 program using ADO, I get a similar message
> if the UserID does not exist or if the UserID does exist
> but does not have the permission to the database.
> The NativeError number is different,
> NativeError - 18456 The UserID does not exist
> NativeError - 4060 The UserID exists, but does not have permission
> to the database.
> Can I hard code the NativeError number in my VB 6
> program to determine exactly what happened,
> (the UserID did not exist or the UserID does exist but
> does not have the proper permission.)
> I worry that the code number might change in a future
> version of sql server.
> I hate to do this but there is no other way to determine
> exactly what happened.
> Thanks in Advance,
> Laurence Nuttall
> Programmer Analyst III
> UCLA - Division of Continuing Education
>
>

Monday, February 27, 2012

Handling out-dated transaction records

For performance issue, I believe many program should have a house-keeping procedure to clean up transaction history. Is there any best practice to perform this? Or should it be done simply by moving transaction data from the transaction table into a history table? Any better or consideration that I should be concerned of?Depends on your environment. Many places would like to keep records for atleast 2 years, but if you are in the medical field and some of your stuff may fall under HIPAA, then you need to keep the records I believe for like 7+ years. In those cases, I usually have an audit table that contains all the transaction data (It's written to via a trigger). Then I keep the transaction table fairly clean (only recent/open/pending), and if you need historical data, then I run my queries off the audit table instead which is never purged and has a good set of indexes on it.

handling nulls with inserts

Hi,

I've got a program that has a form. ?On the form there are several fields which are optional that I would prefer to remain as NULL in the database (rather than a default value) if the user doesn't fill them out. ?I'm using stored procedures for my inserts (sql 2000 + C#). ?

How do most people handle these situations? ?Right now I have a seperate function which receives the parameter values as params and then handles creating the parameters and executing the stored procedure. ?I'm not sure how to handle passing that I want one of those to be null, at least not without having multiple functions and possibly various stored procedures for different possibilities.

Thanks.

I would recommend not using stored procedures if this is what you want to accomplish. Like you said you would have to create multiple stored procedures for each variation. Instead create the insert in your code. I use a string builder to build an SQL statement. Within the logic of your system you can put if then statements to determine what the user inputed and therefore how to build the SQL and correlating params.

Have you tried to pass the value DBNull.Value to the stored procedure? Not sure that this would work, but it might be worth a try if you want to keep your stored procedures.

Hope that helps.