简体   繁体   English

连接字符串定义

[英]Connectionstring definition

ok my ASP.net website is running as long I do not use the database. 好的,只要我不使用数据库,我的ASP.net网站就会运行。 I guess the problem is that I do not really understand the setup of the connectionstring and struggle do find the correct answer. 我猜问题是我不太了解connectionstring的设置,因此我很难找到正确的答案。

My connection string looks like this: "ConnectionStrings" "Add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=aspnetdb;AttachDbFilename=|DataDirectory|\\aspnetdb.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" /" "add name="ApplicationServices" connectionString="Data source=.;Integrated Security=True;Initial Catalog=aspnetdb" /" "/connectionStrings" 我的连接字符串如下所示:“ ConnectionStrings”“添加名称=” DefaultConnection“ connectionString =” Data Source = .;初始目录= aspnetdb; AttachDbFilename = | DataDirectory | \\ aspnetdb.mdf; Integrated Security = SSPI“ providerName =” System。 Data.SqlClient“ /”“添加名称=” ApplicationServices“ connectionString =”数据源= .;集成安全性= True;初始目录= aspnetdb“ /”“ // connectionStrings”

===> I had to change the code as it wouldn't display otherwise (sorry) ===>我不得不更改代码,否则将无法显示(抱歉)

When I run the application and want to login on localhost I get the following error: (website is on the server versus SQL is on the C drive installed): 当我运行该应用程序并想在localhost上登录时,出现以下错误:(网站在服务器上,SQL在安装的C驱动器上):

Database 'C:\\Program Files\\Microsoft SQL Server\\MSSQL11.MSSQLSERVER\\MSSQL\\DATA\\aspnetdb.mdf' already exists. 数据库'C:\\ Program Files \\ Microsoft SQL Server \\ MSSQL11.MSSQLSERVER \\ MSSQL \\ DATA \\ aspnetdb.mdf'已经存在。 Choose a different database name. 选择一个不同的数据库名称。 Cannot attach the file 'S:\\HL\\legaldocsnsw\\WebSite1\\App_Data\\aspnetdb.mdf' as database 'aspnetdb'. 无法将文件“ S:\\ HL \\ legaldocsnsw \\ WebSite1 \\ App_Data \\ aspnetdb.mdf”作为数据库“ aspnetdb”附加。

On the internet there is a database master and my database I created CID05220_aspnetdb: CREATE DATABASE permission denied in database 'master'. 互联网上有一个数据库主数据库,我创建的数据库CID05220_aspnetdb:数据库“主数据库”中的CREATE DATABASE权限被拒绝。 Cannot attach the file 'C:\\inetpub\\vhosts\\legaldocsnsw.com.au\\httpdocs\\App_Data\\aspnetdb.mdf' as database 'aspnetdb'. 无法将文件“ C:\\ inetpub \\ vhosts \\ legaldocsnsw.com.au \\ httpdocs \\ App_Data \\ aspnetdb.mdf”附加为数据库“ aspnetdb”。

How do I have to change the connection string to access these either locally or on the net. 我必须如何更改连接字符串才能本地或通过网络访问它们。 Could someone please help and maybe even explain what I am doing wrong please? 有人可以帮忙,甚至可以解释我做错了吗?

Kind Regards, Rene 亲切的问候,蕾妮

Do you want to use a database that is permanently attached to the SQL Server instance or do you want to attach an MDF file at run time? 是否要使用永久附加到SQL Server实例的数据库,还是要在运行时附加MDF文件? If you want to do the former then get rid of the AttachDbFilename attribute in your connection string. 如果要使用前者,则可以删除连接字符串中的AttachDbFilename属性。 If you want to do the former then you will need a SQL Server Express instance or LocalDB installed on the same machine as the application. 如果要使用前者,则需要在与应用程序相同的计算机上安装SQL Server Express实例或LocalDB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM