Sunday, August 2, 2009

How to connect sql server 2005 express with vb 2005 express?

Hi there, I'm having trouble when connecting the database as i get the error "unable to open the physical file 'C:\Program FIles\Microsoft SQL Server\MSSQL.1\MSSQL\Data\datB... system error 32:'32(the process cannot access the file because it is being used by another process.)'An attempt to attch an auto-named database for file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\datB... failed.A database with the same name exists, or specified file cannot open or it is located on UNC share,"


Im using Windows Authentication and data source(MS SQL Server Database File(SqlClient)


The configuration to allow remote connection has also been done.Im not sure what the problem is.


Btw, Im creating the database using sql server 2005 express





Pls help me on this. Thanks folks!

How to connect sql server 2005 express with vb 2005 express?
This problem happens when one of three things are true:





1. The file is locked by another program, such as the Management Studio console;





2. You have modified the file by uploading it, moving it, renaming it or otherwise having the file system lock the file.





3. You are not using a proper connection string.





It looks to me like you have problem 3; specifically, you are probably using the AttachDataBase parameter in your connection string, which is a bad idea in most cases.





Assuming you are using SqlClient, as you stated, your connection string for a SqlClient connection would be like:





Data Source=.\SQLEXPRESS; Database=Northwind; Integrated Security=True





Please note that you must authenticate as MACHINE\ASPNET, where MACHINE is the name of the server and ASPNET is the name of the ASP.NET worker process (usually aspnet_wp), if you are going to use Windows integrated authentication with your database and you are running an anonymous Web site (that is, you are not using Windows authentication on your site).





If you are using Windows authentication on your site, then every person who logs in to your Web site must have the requisite permissions to access the database resources you use.





Which is why creating a SQL user for your application makes far more sense.





Let's suppose you create a SQL user MYUSER with a password MYPASS. In that case, your connection string becomes:





Data Source=.\SQLEXPRESS; Database=Northwind; User ID=MYUSER; Password=MYPASS;





And that way, you don't have to worry about granting database permissions to every authenticated user, or worse, to the lowly ASP.NET worker process, which by design is normally underprivileged to make life a lot harder on hackers.
Reply:I would suggest changing from Windows authentication, and using SQL authentication. I have never seen anyone successfully utilize the Windows authentication, and it always seems to create problems. To do so, you will have to set up a user account on the SQL Server, and make sure you use the same user name and password for it, and the the connection. Good luck, and please let me know if that doesn't work - I am emailable through YA. Good luck : )


No comments:

Post a Comment