错误“创建文件遇到操作系统错误123”linq vb.net

k97glaaz  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(406)

我有一个链接为“dtschool.dbml”的数据库,我想在运行此代码时在SQLServer中创建此数据库

Dim dt As New SchoolData.linqSchoolsDataContext
    Dim sd As New SqlClient.SqlConnectionStringBuilder
    sd.DataSource = "LAPTOP-AJM33RB1\TESTSERVER"
    sd.IntegratedSecurity = True
    dt.Connection.ConnectionString = sd.ConnectionString
    dt.Connection.Open()
    dt.CreateDatabase()

我看到了这个错误

System.Data.SqlClient.SqlException: 'CREATE FILE encountered operating system error 123(The filename, directory name, or volume label syntax is incorrect.) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL13.TESTSERVER\MSSQL\DATA\|DataDirectory|_Database_Schools_dtSchools.mdf.mdf'.

创建数据库失败。无法创建列出的某些文件名。“检查相关错误。”
错误

gkl3eglg

gkl3eglg1#

使用此方法

Sub CreatesqldatabaseMSQL()
            Try
                Using connect As New DataSchool(Data Source=.;Initial Catalog=DatabaseName;Integrated Security=True)
                    connect.CreateDatabase()
                End Using
            Catch ex As Exception
               MessageBox.Show(ex.Message)
            End Try
        End Sub

相关问题