数据库未创建 [英] Database not created

查看:97
本文介绍了数据库未创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

When I run application error not display but stop on this line Sqlcon.Open()
Because app.Config not run properly therefore database not created. Generate script
File is "C:\Create\SQLScriptDetail.sql"





我试过的:





What I have tried:

Config file

<configuration>
  <appSettings>
    <add key="SQLSqriptRead" value="C:\Create\SQLScriptDetail.sql"/>
  </appSettings >
  <connectionStrings>
    <add name="RMS.My.MySettings.StupConnection" connectionString="Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=SQLSqript;Integrated Security=true;User ID=sa;Password=" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Imports System.Data.SqlClient
Imports System.Configuration

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim SQLConnectionString As String = ConfigurationManager.ConnectionStrings("RMS.My.MySettings.StupConnection").ConnectionString
        System.Configuration.ConfigurationManager.AppSettings.Get("SQLSqriptRead")

        Using Sqlcon As New SqlConnection(SQLConnectionString)
            Sqlcon.Open()

            Dim Check_User_Name_Found As New SqlClient.SqlCommand("Select Max(Name) from SQLSqript.dbo.Script", Sqlcon)
            Dim Check_UserNameFound = Check_User_Name_Found.ExecuteScalar().ToString()

       End Using

    End Sub
End Class

推荐答案

猜测 - 我没有任何访问你的数据库,所以我无法检查 - 你试图在试图连接到它的代码中创建一个数据库。这不会起作用,除非数据库已经存在,并且错误消息表明它不存在。



您需要做的是连接到数据库引擎没有指定要使用的数据库。

目前你的连接字符串指定了一个数据库:

At a guess - and I haven't got any access to your database so I can't check - you are trying to create a database in code that tries to connect to it. That won't work, not unless the DB already exists, and the error message would indicate it doesn't.

What you need to do is connect to the database engine without specifying a DB to use.
At the moment your connection string specifies a DB:
Data Source=Computech-PC\SQLEXPRESS;Initial Catalog=SQLSqript;Integrated Security=true;User ID=sa;Password='' providerName=System.Data.SqlClient"
                                    \_______________________/
                                              DB

Use String。替换以删除该部分,它应该开始工作,但您可能需要整理授权 - 集成安全性和用户名和密码是不寻常的,您可能根本不需要ProviderName部分。

Use String.Replace to remove that section and it should start to work, but you probably need to sort out the authorization - Integrated Security and a username and password is unusual, and you probably don't want the ProviderName section at all.


这篇关于数据库未创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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