Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Thursday, March 8, 2012

Connection failed!

Hi guys,

I have problem with this code:

TCHAR szCurrentDir[250];

TCHAR szDataDir[250];

lstrcpy(szDataDir,

TEXT("DRIVER={SQL Native Client};SERVER=.\\sqlexpress;Trusted_Connection=Yes;DATABASE=MyDic;AttachDBFileName="));

GetCurrentDirectory(sizeof(szCurrentDir), szCurrentDir);

lstrcat(szCurrentDir, TEXT("\\Database\\Data.mdf;"));

lstrcat(szDataDir, szCurrentDir);

SQLDriverConnect(hdbc, hWnd, szDataDir, SQL_NTS, szConnStrOut, sizeof(szConnStrOut), &cbConnStrOut, SQL_DRIVER_COMPLETE);

When I run my program, I get this message:


Microsoft SQL Server Login
Connection failed:
SQLState: '42000'
SQL Server Error: 5133
[Microsoft][SQL Native Client][SQL Server]Directory lookup for the file "C:\Program Files\MyDic\Database\Data.mdf" failed with the operating system error 5(Access is denied.).
Connection failed:
SQLState: '42000'
SQL Server Error: 1832
[Microsoft][SQL Native Client][SQL Server]Could not attach file 'C:\Program Files\MyDic\Database\Data.mdf' as database 'MyDic'.


OK

I have to mention that:

SQL Server: SQL Server (2005) Express

Operating System: Windows XP SP2

and I'm Local Admin.

I wanna deploy this program with data.mdf file that contains program data.

So, How can I fix it?

Regards

Curious issue. It looks like your connection string is correct. Can you check to see if your detached database's assocated .LDF file is read-only? (I had that issue before.) If it doesn't have one, then ignore this suggestion.

Another thing you might try is to see if putting your detached database into the SQL Server's 'Data' folder. Something along the lines of 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data'. Again, probably not the issue since you're getting an 'access denied' error, not one about 'file not found'.

Did you detach with same version SQL server? This could be a compatibility issue.

It almost sounds like you're trying to attach a database that already exists. Could this be possible?

Try to debug your issue with the following steps:

1) Create a database, with tables, etc...

2) Detach the database

3) drop the database

4) try to re-attach the database using a connection string like the one above.

If you can get this to work then you should be okay.

If you're still stuck, re-activate this issue and I'll try to think of something else.

~Warren

|||Does C:\Program Files\MyDic\Database\Data.mdf exist? Does the service account for your sqlexpress has permissions to read/write this file? You must have at least read permission to the file to logon to the server. (You cannot relay on sqlexpress create the file for you.)|||

Dear Warren,

I have checked all things you mentioned, but it doesn't work

I think this issue is concerned with the service account for my SQLEXPRESS as Xinwei Hong mentioned.

Well, Do you know how I can change this account programmatically so that I could get rid this issue?

Best

|||

Dear Xinwei,

I think you are right. But how can I change the service account programmatically in order to have read and write permission?

Thanks,

|||

I don't think you need to change the service account programmatically. You can just give the read/write permission to the service account. Do you have any special reason that you don't want to give the permission to the SQL service account on your computer?

Thanks.

|||

That's a tough one. I guess the easiest way would be to create an 'sa' login on your SQL Server installation, and then replace 'Trusted_Connection' with 'User=sa;Pwd=<<WhateverPasswordYouCreated>>;'.

This would guarantee you have admin rights to attach/detach databases.

Second easiest would be to log onto machine as admin, and add your user name as a machine admin. (I’m afraid I’m not too good at showing how to do that on an XP machine, since I only use W2K3 Server.)

The more difficult method to do this programmatically would be to use “Runas”. I’m not positive it would work, but you could try running your application from the command line via ‘Runas admin’ which would give it admin rights, and it should work. Please see http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true for more documentation on how to use this.

If anyone else has suggestions, please speak up!

Good luck!

~Warren

|||

Hi Xinwei,

As I said before, I just wanna deploy my program containing data.mdf file. I made installation and I tested but I got this problem. I read some technique to deploy MDF files such az Xcopy, but it didn't work.

sincerely.

|||

Hi Warren,

Thank you for your comments.

By the way, I read this article:

"How to verify and change the system administrator password in MSDE or SQL Server"

http://support.microsoft.com/Default.aspx?scid=kb;en-us;322336&spid=2855&sid=global

But when I created sa, sqlcmd said that sa account disabled. Do you know how I can enable it?

Thanks.

|||

Look here:

http://msdn2.microsoft.com/en-us/library/ms188670.aspx

|||

Dear Markus,

Thank you so much. I got that.

Regards.

Wednesday, March 7, 2012

connection failed

This is a multi-part message in MIME format.
--=_NextPart_000_0006_01C83047.CA2BAB90
Content-Type: text/plain;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable
Hi,
I have a program using ms sql. It worked fine for some time, but
now each time the program access the databases it outputs "Connection = Failed
SQLState 28000, SQL Server Error 18456, Login failed for user 'sa'".
After pressing OK it gives an option to input a new password manually, = and after
entering it - it works. But only for the current transaction. Next time = it'll prompt again.
I've tried to change the password, I've chaned it in the system ODBC = drivers, tried different usernames, but the same error returns.
What could be the problem ?
Thanks.
--=_NextPart_000_0006_01C83047.CA2BAB90
Content-Type: text/html;
charset="windows-1255"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&
Hi,
I have a program using ms sql. It = worked fine for some time, but
now each time the program access the = databases it outputs "Connection Failed
SQLState 28000, SQL Server Error 18456, = Login failed for user 'sa'".
After pressing OK it gives an option to = input a new password manually, and after
entering it - it works. But only for = the current transaction. Next time it'll prompt again.

I've tried to change the password, I've = chaned it in the system ODBC drivers, tried
different usernames, but the = same error returns.

What could be the problem = ?
Thanks.
--=_NextPart_000_0006_01C83047.CA2BAB90--It depends on the said program. How the program is configured or coded to
connect to the SQL Server database? It sounds the program is configured or
hard-coded (too bad!!!) with "sa/sapassword" to connect. The reason of error
is bacause "sa" account's password has been changed, which is good (maybe
the DB admin knew some apps use "sa" to access the SQL Server, which is bad
practice, and he changed it?).
You must find a way to reconfigure it to use new password. If the password
is hard coded, then you may out luck to change it easily.
"Marius Kaizerman" <marius@.kaizerman.org> wrote in message
news:e9e%23NcDMIHA.4712@.TK2MSFTNGP04.phx.gbl...
Hi,
I have a program using ms sql. It worked fine for some time, but
now each time the program access the databases it outputs "Connection Failed
SQLState 28000, SQL Server Error 18456, Login failed for user 'sa'".
After pressing OK it gives an option to input a new password manually, and
after
entering it - it works. But only for the current transaction. Next time
it'll prompt again.
I've tried to change the password, I've chaned it in the system ODBC
drivers, tried
different usernames, but the same error returns.
What could be the problem ?
Thanks.|||Norman,
You were absolutely right.
Thanks alot!
"Norman Yuan" <NoAddress@.NoEmail.fake> wrote in message
news:OonyLvDMIHA.1164@.TK2MSFTNGP02.phx.gbl...
> It depends on the said program. How the program is configured or coded to
> connect to the SQL Server database? It sounds the program is configured or
> hard-coded (too bad!!!) with "sa/sapassword" to connect. The reason of
> error is bacause "sa" account's password has been changed, which is good
> (maybe the DB admin knew some apps use "sa" to access the SQL Server,
> which is bad practice, and he changed it?).
> You must find a way to reconfigure it to use new password. If the password
> is hard coded, then you may out luck to change it easily.
>
> "Marius Kaizerman" <marius@.kaizerman.org> wrote in message
> news:e9e%23NcDMIHA.4712@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I have a program using ms sql. It worked fine for some time, but
> now each time the program access the databases it outputs "Connection
> Failed
> SQLState 28000, SQL Server Error 18456, Login failed for user 'sa'".
> After pressing OK it gives an option to input a new password manually, and
> after
> entering it - it works. But only for the current transaction. Next time
> it'll prompt again.
> I've tried to change the password, I've chaned it in the system ODBC
> drivers, tried
> different usernames, but the same error returns.
> What could be the problem ?
> Thanks.

Friday, February 24, 2012

Connection Breaks on StProc text UPDATE

Hi,
We have a simple stored procedure that has a text parameter, among others.
Inside the procedure the text parameter is assigned to a text column in a
simple SET clause of a simple UPDATE statement. We pass a 15 character
string as an argument for the parameter, and even though the string is
stored to the table, we get this error message (running in Query
Analyzer)...
*-*-*-*
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
(CheckforData()).
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation.
Connection Broken
*-*-*-*
Any of the following make the error message go away...
1) Pass NULL as the argument
2) Comment out the assignment in the SET clause
3) Change the parameter to varchar(8000)
Anyone have any ideas?
--
Thank you,
Daniel Jameson
Children's Oncology Group
http://www.childrensoncologygroup.orgCan you show the CREATE TABLE statement and the CREATE PROCEDURE code?
Also, tell us the result of SELECT @.@.VERSION
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"danjam" <djameson@.childrensoncologygroup.org> wrote in message
news:e6y2#eMxDHA.3416@.tk2msftngp13.phx.gbl...
> Hi,
> We have a simple stored procedure that has a text parameter, among others.
> Inside the procedure the text parameter is assigned to a text column in a
> simple SET clause of a simple UPDATE statement. We pass a 15 character
> string as an argument for the parameter, and even though the string is
> stored to the table, we get this error message (running in Query
> Analyzer)...
> *-*-*-*
> [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
> (CheckforData()).
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation.
> Connection Broken
> *-*-*-*
> Any of the following make the error message go away...
> 1) Pass NULL as the argument
> 2) Comment out the assignment in the SET clause
> 3) Change the parameter to varchar(8000)
> Anyone have any ideas?
> --
> Thank you,
> Daniel Jameson
> Children's Oncology Group
> http://www.childrensoncologygroup.org
>|||There are some known bugs that cause this or similar errors - it would
help to see your stored procedure. It could be an issue with UNION,
with an INSTEAD OF trigger, certain query structures, or an unknown
bug... It does sound like a bug, though.
SK
danjam wrote:
>Hi,
>We have a simple stored procedure that has a text parameter, among others.
>Inside the procedure the text parameter is assigned to a text column in a
>simple SET clause of a simple UPDATE statement. We pass a 15 character
>string as an argument for the parameter, and even though the string is
>stored to the table, we get this error message (running in Query
>Analyzer)...
>*-*-*-*
>[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
>(CheckforData()).
>Server: Msg 11, Level 16, State 1, Line 0
>General network error. Check your network documentation.
>Connection Broken
>*-*-*-*
>Any of the following make the error message go away...
> 1) Pass NULL as the argument
> 2) Comment out the assignment in the SET clause
> 3) Change the parameter to varchar(8000)
>Anyone have any ideas?
>
>|||Steve,
Thank you for responding. I have posted additional info under Aaron's post.
I do have an INSTEAD of trigger, but there are no UNION's involved.
--
Thank you,
Daniel Jameson
Children's Oncology Group
http://www.childrensoncologygroup.org
"Steve Kass" <skass@.drew.edu> wrote in message
news:uIFJ5pMxDHA.2556@.TK2MSFTNGP10.phx.gbl...
> There are some known bugs that cause this or similar errors - it would
> help to see your stored procedure. It could be an issue with UNION,
> with an INSTEAD OF trigger, certain query structures, or an unknown
> bug... It does sound like a bug, though.
> SK
> danjam wrote:
> >Hi,
> >
> >We have a simple stored procedure that has a text parameter, among
others.
> >Inside the procedure the text parameter is assigned to a text column in a
> >simple SET clause of a simple UPDATE statement. We pass a 15 character
> >string as an argument for the parameter, and even though the string is
> >stored to the table, we get this error message (running in Query
> >Analyzer)...
> >
> >*-*-*-*
> >[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionCheckForData
> >(CheckforData()).
> >Server: Msg 11, Level 16, State 1, Line 0
> >General network error. Check your network documentation.
> >
> >Connection Broken
> >*-*-*-*
> >
> >Any of the following make the error message go away...
> > 1) Pass NULL as the argument
> > 2) Comment out the assignment in the SET clause
> > 3) Change the parameter to varchar(8000)
> >
> >Anyone have any ideas?
> >
> >
> >
>