Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Friday, February 24, 2012

Can't connect using SqlClient after creating new database.

Hi,

I am writing a c# console application that allows you to update a database to a specified version. It does this by running a set of scripts that are listed in an xml manifest.

The application also provides an option to create the database and then run scripts to update it.

I have a method that reads blocks of SQL from each script and runs them using the ADO.NET classes in the SqlClient namespace.

I am finding that after the application runs the script to create the database, the first time the application tries to connect to that new database the connection attempt fails. The error I receive is :-

Cannot open database {dbname} requested by the login. The login failed.
Login failed for user {user}

I find that if I set the thread to sleep for 3 seconds after the database is created, I can then connect without the error occurring, but this is a bit of a nasty hack. I'd prefer to find a better solution.

This is occurring against a local SQL Server Express instance.

My machine is reasonable. 3.4 Ghz. 2Gb RAM, so I wouldn't have thought there's any problems in that regard.

Does anyone have any pointers, firstly as to why this is occurring, and secondly, how I might solve this problem in a nicer way?

Thanks,

David.

Hi David,

This is strange behaviour. Are you using Windows auth or SQL auth? Also, are there any errors written to your error log?

Thanks,
Il-Sung.

|||

Hi ll-Sung,

Sorry it has taken so long for me to get back to you about this.

My SQL Express is set up for Windows Auth only, and I am connecting as such.

The exception I receive when I try to connect after creating the database is :-

Cannot open database "DatabaseName" requested by the login. The login failed.

Login failed for user 'Domain\UserName'.

Both the SQL Log and the Windows Event Log display a series of informational messages that occur during the creation of the database. Things like :-

Setting database option ANSI_PADDING to OFF for database DatabaseName

Also in the logs, I receive a Failure Audit error message. This occurs before any of the informational messages occur. It looks like :-

Login failed for user 'Domain\UserName'. [CLIENT: <local machine>]

However this login failure message appears whether or not the database creation succeeds or not (ie the process succeeds when I have my Sleep command in).

So overall, I guess there is no error in any of the logs indicating why this is occurring.

The SQL I am using to create the database is a script that I made simply by scripting off the db in Management Studio. I did not muck around with this at all except to put placeholders in for the database name.

Any further help you can provide for this would be much appreciated.

Thanks,

David.

Can''t Connect to SQl via Windows NT Network

Help!

I'm writing some VB.net 2005 windows applications which connect to various tables within SQL Server 2005.

If my programs are running from C drive, I have no problems connecting to my database.

but if i run my exe file from a network drive, then the SQL server doesnt recognise the user's pc, and wont allow my program to access any data.

Can anyone help me with this problem?

What is the exact error message you came across?

Can you answer the question according to the following guidance?

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=362498&SiteID=1

Good Luck!

Ming.

|||I guess you are receiving exception due to security restrictions, right ? This is caused by the CAS defined for network locations making it not possible to use all applications / assemblies from network ressources.

Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

The problem was solved by adding a strong name when publishing the program.

Tuesday, February 14, 2012

Cant connect to MSDE on XPSP1

We are writing a setup program for a customer that requires a MSDE
installation.
Using the following flags for the MSDE setup.exe:
SAPWD = "password" SECURITYMODE=SQL
The setup complete successfully, we are restarting the installed machine
(SQL services restarts as well)
But we cannot connect to the MSDE from any enterprise manager (Enterprise,
Developer versions)
This happens only when the MSDE installed on a WindowsXP SP1 machine.
Can someone help us solve this problem?
Thanks,
Shif
It may be that you don't have any network protocols enabled for MSDE. Run
the tool svrnetcn.exe (you'll find it in C:\Program Files\Microsoft SQL
Server\80\Tools\Binn) and check to make sure that you have the necessary
protocols enabled.
Jim
"Shif Arad" <shif@.inter.net.il> wrote in message
news:Om8nd%23vJEHA.2604@.tk2msftngp13.phx.gbl...
> We are writing a setup program for a customer that requires a MSDE
> installation.
> Using the following flags for the MSDE setup.exe:
> SAPWD = "password" SECURITYMODE=SQL
>
> The setup complete successfully, we are restarting the installed machine
> (SQL services restarts as well)
> But we cannot connect to the MSDE from any enterprise manager (Enterprise,
> Developer versions)
> This happens only when the MSDE installed on a WindowsXP SP1 machine.
>
> Can someone help us solve this problem?
> Thanks,
> Shif
>

Cant connect to MSDE on XPSP1

We are writing a setup program for a customer that requires a MSDE
installation.
Using the following flags for the MSDE setup.exe:
SAPWD = "password" SECURITYMODE=SQL
The setup complete successfully, we are restarting the installed machine
(SQL services restarts as well)
But we cannot connect to the MSDE from any enterprise manager
(Enterprise,Developer versions)
This happens only when the MSDE installed on a WindowsXP SP1 machine.
Can someone help us solve this problem?
Thanks,
Shif
Verify that the MSDE is listening on TCP/IP. Check the NT Application logs
after MSDE is started.
If it's only listening on Shared Memory, then only local connections will
succeed.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
|||Hi,
How can i change this option AND in what menu should i look for it ?
Thank
Javier A. Junca Barreto.
Desarrollo de Sistemas
SICyA Software.
Web: www.sicya.com
Mail: desarrollo@.sicya.com
Tel: (57 1) 272 0738
|||MSDE doesn't ship with any utilities. So, you could change this via the
registry.
Check the following registry key on your server:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSDE Name Here
\MSSQLServer\SuperSocketNetLib
Add np and or tcp to the ProtocolList value.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.

Cant connect to MSDE on XPSP1

We are writing a setup program for a customer that requires a MSDE
installation.
Using the following flags for the MSDE setup.exe:
SAPWD = "password" SECURITYMODE=SQL
The setup complete successfully, we are restarting the installed machine
(SQL services restarts as well)
But we cannot connect to the MSDE from any enterprise manager
(Enterprise,Developer versions)
This happens only when the MSDE installed on a WindowsXP SP1 machine.
Can someone help us solve this problem?
Thanks,
ShifVerify that the MSDE is listening on TCP/IP. Check the NT Application logs
after MSDE is started.
If it's only listening on Shared Memory, then only local connections will
succeed.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.|||Hi,
How can i change this option AND in what menu should i look for it ?
Thank
Javier A. Junca Barreto.
Desarrollo de Sistemas
SICyA Software.
Web: www.sicya.com
Mail: desarrollo@.sicya.com
Tel: (57 1) 272 0738|||MSDE doesn't ship with any utilities. So, you could change this via the
registry.
Check the following registry key on your server:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Mi
crosoft SQL Server\MSDE Name Here
\MSSQLServer\SuperSocketNetLib
Add np and or tcp to the ProtocolList value.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.