等待sqlservr加载然后执行程序 [英] wait for sqlservr to load and then execute program

查看:72
本文介绍了等待sqlservr加载然后执行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我想等待sql server(sqlservr)的进程首先加载,然后执行我的程序,我发现了一些代码,但是它正在启动一个进程,当它闲置时执行其余的代码

Hello,
I want to wait for process of the sql server (sqlservr) to load first and then execute my program, I found some code but it is starting a process and when put to idle executes the remainning code

process.start("notepad.exe").waitforinputidle


它可以工作,但是我想检查sqlservr何时完全加载,然后执行.有帮助吗?

谢谢
Kyriakos


it works but I want to check when sqlservr loads completely and then execute. Any help?

Thank you
Kyriakos

推荐答案

不,不是真的.

SQL Server本身不是一个应用程序,它是组成服务的一组应用程序.您无需启动" SQL Server,它会在Windows加载时加载某些部分,并坐在那里等待请求.

因此,在执行程序之前谈论启动和等待其加载有点荒谬.

您认为需要这样做是什么?


我正在尝试将程序启动,它连接到sql数据库并添加了edits删除记录,但是当我将其加载到sql server之前并且无法连接时,我尝试了sleep(seconds),但是有时在加载之前,有时在加载之后,这有点不舒服.所以我想先加载sql server,然后再从启动中加载程序,以便正确连接."

您是否尝试过检查实例是否准备就绪?
我没有检查过,但是,如果您与Sleep(500)处于循环中并列出当前实例,则应该能够看到SQL Server准备就绪的时间:
No, not really.

SQL server is not an application as such, it is a set of applications which make up a service. You don''t "start" SQL server, it loads some portions when Windows loads, and sits there waiting for requests.

So it is a bit nonsense to talk about starting and waiting for it to load before executing your program.

What are you trying to do that you think this is needed?


"I am trying to put my program to startup, it connects to an sql database and adds edits deletes records, but when I put it it loads before sql server and cannot connect to it, I have tried sleep(seconds) but it is a little uncomfortable sometimes loads before sometimes after. So I want to load sql server first and then my program from startup so it is connected properly."

Have you tried checking if the instance is ready?
I haven''t checked this, but, if you sit in a loop with Sleep(500) and list the current instances, you should be able to see when SQL server is ready:
Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim dt As DataTable = instance.GetDataSources()
For Each row As System.Data.DataRow In dt.Rows
    Console.WriteLine("ServerName = {0}", row("ServerName"))
Next

如果将服务器名称与所需的服务器名称进行核对,那么当它出现时,它应该已准备就绪,可以开始"n"滚动.

If you check the server name against the one you want, then when it appears it should be ready to rock ''n'' roll.


那是错误的解决这个问题的方法.在启动时,您的应用程序应首先尝试连接到数据库,如果它没有响应,请等待并重试.在此放置最大数量的重试,两次尝试之间可能需要等待5秒钟.数据库一旦数据库响应,就可以继续.如果重试次数已用完,则出现错误.
That''s the wrong way to approach this. On startup, your app should try to connect to the database first, and if it doesn''t respond, wait and try again. Put a maximum number of retries in there and maybe a 5 second wait between tries. Once database the database responds, you can proceed. If the number of retries is exhausted, then put up an error.


这篇关于等待sqlservr加载然后执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆